需要测试时间的代码
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
#region
需要测试的代码
#endregion
stopwatch.Stop();
TimeSpan timeSpan = stopwatch.Elapsed;
double seconds = timeSpan.TotalSeconds;
Console.WriteLine("文件读取的总秒数为:{0}", seconds);
键值对数据排序
SortedDictionary<DateTime, String> dd = new SortedDictionary<DateTime, String>();
DateTime dt = DateTime.Now;
dd.Add(dt, "bbb");
dd.Add(dt.AddDays(-1), "ccc");
dd.Add(dt.AddDays(1), "aaa");
List<String> lst = new List<String>(dd.Values);
lst.Reverse();
Dictionary<DateTime, String> dd = new Dictionary<DateTime, String>();
DateTime dt = DateTime.Now;
dd.Add(dt, "bbb");
dd.Add(dt.AddDays(-1), "ccc");
dd.Add(dt.AddDays(1), "aaa");
var result = from pair in dd orderby pair.Key descending select pair;
List<String> lst = new List<String>();
foreach (var kv in result)
{
lst.Add(kv.Value);
}
Dictionary<DateTime, String> dd2 = result.ToDictionary(p=>p.Key, p=>p.Value);
Dictionary<DateTime, String> dd = new Dictionary<DateTime, String>();
DateTime dt = DateTime.Now;
dd.Add(dt, "bbb");
dd.Add(dt.AddDays(-1), "ccc");
dd.Add(dt.AddDays(1), "aaa");
Dictionary<DateTime, String> dicAsc = dd.OrderBy(p=>p.Key).ToDictionary(p=>p.Key, p=>p.Value);
Dictionary<DateTime, String> dicDesc = dd.OrderByDescending(p=>p.Key).ToDictionary(p=>p.Key, p=>p.Value);
文件读写
StreamWriter log = new StreamWriter(@"E:\wli\send.txt");
FileStream fsw = new FileStream(@"E:\wli\tmp.zip", FileMode.OpenOrCreate,FileAccess.Write);
FileStream fs = new FileStream(@"E:\wli\mdl_3_4_0.zip", FileMode.OpenOrCreate);