首页 > 代码库 > 字典的排序

字典的排序

Dictionary<string, string> dic1 = new Dictionary<string, string>();
dic1.Add("ddd","123");
dic1.Add("aaa", "123");
dic1.Add("ccc", "123");
dic1.Add("fff", "123");
dic1.Add("eee", "123");
dic1.Add("bbb", "123");
Dictionary<string, string> dic1Asc = dic1.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
Dictionary<string, string> dic1desc = dic1.OrderByDescending(o => o.Key).ToDictionary(o => o.Key, p => p.Value);

字典的排序