c#知识点

2018-01-18  本文已影响44人  wwmin_

记录自己在学习c#遇到的知识点(容易忽略容易忘记得,或一些小技巧)

public HttpResponseMessage reportsExcel(HttpRequestMessage request,[FromUri] ExportParam param){

}
//其中ExportParam 类
    public class ExportParam : ReportSearchParam
    {
        public string title { get; set; }
        public string companyName { get; set; }
        public DateTime date { get; set; }
        public string[] tableTitles { get; set; }
    }

此时,参数可以传递数组,但是数组的在url上的写法应是{{server}}Export/reportsExcel?companyId=1&startDate=2018-1-1&endDate=2018-2-1&title=测试&companyName=公司&date=2017-1-18&tableTitles=1111&tableTitles=aaa,即,将数组参数重复写

/// <summary>
/// Writes an error level logging message.
/// </summary>
/// <param name="message">The message to be written.</param>
public void WriteError(object message,
[CallerMemberName] string memberName = "",//调用函数名称
[CallerFilePath] string sourceFilePath = "",//调用文件
[CallerLineNumber] int sourceLineNumber = 0 //调用行号)
{
    _log4Net.ErrorFormat("文件:{0} 行号:{1} 方法名:{2},消息:{3}", sourceFilePath, sourceLineNumber, memberName, message);
 }
Dictionary<string, string> MyDictionary = new Dictionary<string, string>();
MyDictionary = (from entry in MyDictionary 
    orderby entry.Value ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
/// <summary>  
/// 获取随机数
/// </summary>  
/// <returns></returns>  
private static string GetRandom()
{
    Random rd = new Random(DateTime.Now.Millisecond);
    int i= rd.Next(0,int.MaxValue);
    return i.ToString();
}
/// <summary>  
/// 获取时间戳  
/// </summary>  
/// <returns></returns>  
private static string GetTimeStamp()
{
    TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
    return Convert.ToInt64(ts.TotalMilliseconds).ToString();
}
上一篇 下一篇

猜你喜欢

热点阅读