码迷,mamicode.com
首页 > 其他好文 > 详细

字典Dictionary

时间:2018-10-09 11:42:16      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:order   div   linq   asc   bsp   pair   entry   pre   code   

 

Dictionary排序

对一个Dictionary<TKey, TValue>进行排序可以用LINQ:

Dictionary<string, string> MyDictionary = new Dictionary<string, string>();


1、键排序

MyDictionary = (from entry in MyDictionary 
                                     orderby entry.Key ascending
                                     select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

 

2、值排序

MyDictionary = (from entry in MyDictionary 
                                     orderby entry.Value ascending
                                     select entry).ToDictionary(pair => pair.Key, pair => pair.Value);

 

字典Dictionary

标签:order   div   linq   asc   bsp   pair   entry   pre   code   

原文地址:https://www.cnblogs.com/code1992/p/9759249.html

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