码迷,mamicode.com
首页 > 编程语言 > 详细

c# 字典表排序

时间:2014-11-05 12:19:05      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   sp   

原文链接 :http://blog.csdn.net/xxj_jing/article/details/8005683

bubuko.com,布布扣
      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 = "";
View Code

 

c# 字典表排序

标签:des   style   blog   http   io   color   ar   os   sp   

原文地址:http://www.cnblogs.com/chengjunwei/p/4075753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!