k.key, v => v.value)">
当前位置:   article > 正文

C# Dictionary(字典)的键、值排序

dictionary union dictionary todictionary(k => k.key, v => v.value)


      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 = "";




转载于:https://www.cnblogs.com/xxj-jing/archive/2012/09/21/2890048.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/84450
推荐阅读
相关标签
  

闽ICP备14008679号