使用List对其进行排序

using System; using System.Collections.Generic; using System.Text;

namespace ConsoleApplication4 {     class Program     {         static void Main(string[] args)         {

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

dic.Add("Arraymin", "c:\\demo\\min.xsl");

dic.Add("Arraymax", "c:\\demo\\max.xsl");

dic.Add("Arrayr", "c:\\demo\\r.xsl");

List<KeyValuePair<string, string>> myList = new List<KeyValuePair<string, string>>(dic);

myList.Sort(delegate(KeyValuePair<string, string> s1, KeyValuePair<string, string> s2)                 {

return s1.Value.CompareTo(s2.Value);

});

dic.Clear();

foreach (KeyValuePair<string, string> pair in myList)             {

dic.Add(pair.Key, pair.Value);

}

foreach (string key in dic.Keys)             {

Console.WriteLine(dic[key]);

}

Console.ReadKey();         }            } }

C#3.0 Lambda表达式 (VS2008)的实现方法:

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

dic.Add("Arraymin", "c:\\demo\\min.xsl");

dic.Add("Arraymax", "c:\\demo\\max.xsl");

dic.Add("Arrayr", "c:\\demo\\r.xsl");

var list = dic.OrderBy(s => s.Value);

foreach (var s in list)

{

Console.WriteLine(dic[key]);            }

C#3.0 Linq (VS2008)的实现方法:

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

dic.Add("Arraymin", "c:\\demo\\min.xsl");

dic.Add("Arraymax", "c:\\demo\\max.xsl");

dic.Add("Arrayr", "c:\\demo\\r.xsl");

var dicSort = from d in dic

orderby d.Value

ascending

select d;

foreach (string key in dic.Keys)

{

Console.WriteLine(dic[key]);

}

参考:http://blog.csdn.net/meifage2/article/details/6623272

转载于:https://www.cnblogs.com/xiaoN-2006/p/3353147.html

C#对Dictionary的按Value排序相关推荐

  1. c# Dictionary的遍历和排序

    c# Dictionary的遍历和排序 c#遍历的两种方式 for和foreach for: 需要指定首位数据.末尾数据.数据长度: for遍历语句中可以改变数据的值: 遍历规则可以自定义,灵活性较高 ...

  2. python dictionary排序_对Python的字典进行排序

    我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...

  3. python字典怎么排序_如何对python的字典进行排序

    我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...

  4. python dict sorted 排序

    我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...

  5. C# Hashtable和Dictionary区别

    Hashtable和Dictionary都是.Net下的表示键值对的集合,那么我们在使用中该选择Hashtable还是Dictionary?下边我们看看他们之间的区别: 1.Dictionary< ...

  6. python字典按键值排序_在Python中按键或值按升序和降序对字典排序

    python字典按键值排序 Problem Statement: Write a Python program to sort (ascending and descending) a diction ...

  7. python中排序的函数_Python中sorted()排序函数

    语法: sorted(iterable, key=None, reverse=False) *iterable:可迭代的对象 *key:用来排序的元素,可以通过函数指定 *reverse:排序规则,r ...

  8. python字典排序并输出_对Python的字典进行排序

    我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...

  9. Python 列表、字典、元组的一些小技巧

    1. 字典排序 我们知道 Python 的内置 dictionary 数据类型是无序的,通过 key 来获取对应的 value.可是有时我们需要对 dictionary 中的 item 进行排序输出, ...

  10. python dict sorted

    1. 准备知识: 在python里,字典dictionary是内置的数据类型,是个无序的存储结构,每一元素是key-value对: 如:dict = {'username':'password','d ...

最新文章

  1. pycharm执行python程序报错ImportError: DLL load failed: torchvision找不到指定的程序
  2. 使用MongoDB进行乐观锁定重试
  3. 将Glassfish 3连接到外部ActiveMQ 5代理
  4. 图解安装CentOS 6.6
  5. TikZ绘图示例——尺规作图: 圆内接任意正边形的近似画法(以正七边形为例)
  6. 微软语音 AI 技术与微软听听文档小程序实践 | AI ProCon 2019
  7. java listt add_Java8 使用流抽取ListT集合中T的某个属性操作
  8. 强大的日志分析工具AWStats
  9. 无人驾驶车辆模型预测控制配套代码_代码详解——最简NMPC路径跟踪仿真代码...
  10. python做什么生意好找_寻找python项目来提高你的技能
  11. 全球IT经理一致喜爱的ITSM系统、it服务台软件
  12. 泛微OA流程附件在服务器磁盘中的位置
  13. SQLite 查询得到今天日期
  14. android 活动生命,Android 活动生命周期
  15. 计算机英语性考任务答案,国开电大理工英语1单元自测2形考任务答案
  16. ant design vue table 高度自适应_很受欢迎的vue前端UI框架
  17. VisualDMIS 6.5探测误差程序(25点球)
  18. 计算机中人民币符号在哪儿,人民币符号电脑怎么打(如何在文档中输入人民币符号)...
  19. 马士兵 java se_马士兵javase(170804)
  20. 基于5G+MEC的电站行业专网部署方案研究

热门文章

  1. 不做律师,玩起了电子合同,这家入选微软加速器第十期的电子合同企业究竟是什么来头?
  2. bash, sh, dash 傻傻分不清楚
  3. 提升网站权重优化方法,网站权重优化步骤
  4. python 数字转换为汉字大写
  5. rd640服务器引导,ThinkServer RD640 OS安装手册 V1.4.pdf
  6. annotate 函数的用法
  7. python模拟手机app签到_利用 Python + Selenium 实现自动登陆签到
  8. 人体关节正常活动范围
  9. 读《把时间当作朋友:运用心智获得解放》
  10. 基于贪心选择及斜率探测扩充的轨面提取方法