C# 中使用Linq 对Dictionary进行排序

作者:互联网   出处:控件中国网   2014-11-05 19:21:29   阅读:1

C# 中使用Linq 对Dictionary进行排序

                 Dictionary<string, int> letterWordTotalNum = wordsMrg.GetAllLetterTotalNum();
                var dicSort = from d in letterWordTotalNum
                                  orderby d.Key 
                                  select d;

               foreach (string key in dicSort.Keys)
                      {

                      s    Response.Write(dicSort[key] + "<br />");

                       }

按key进行升序排列,如需将序排列,则 orderby d.Key  descending,排序之后仍然是一个键值对的集合。

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat