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,排序之后仍然是一个键值对的集合。

posted @ 2011-05-08 20:04  泪的诺言lni  阅读(2038)  评论(0编辑  收藏  举报