首页 > 代码库 > c# 字典表排序
c# 字典表排序
原文链接 :http://blog.csdn.net/xxj_jing/article/details/8005683
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); Dictionary<string, string> dic1Asc1 = (from d in dic1 orderby d.Key ascending select d).ToDictionary(k => k.Key, v => v.Value); Dictionary<string, string> dic1desc2 = (from d in dic1 orderby d.Key descending select d).ToDictionary(k => k.Key, v => v.Value); List<string> list = new List<string>(); list.Add("aaa"); list.Add("ddd"); list.Add("bbb"); list.Add("ccc"); list.Add("bbb"); var ascList = list.OrderBy(o => o); var descList = list.OrderByDescending(o => o); var ascList1 = (from l in list orderby l ascending select l).ToList(); var descList2 = (from l in list orderby l descending select l).ToList(); string str = "";
c# 字典表排序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。