使用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

C#对Dictionary的按Value排序的更多相关文章

  1. c# Dictionary的遍历和排序

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

  2. c# Dictionary的遍历和排序(转)

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

  3. C#对 Dictionary进行排序 转

    C# .net 3.5 以上的版本引入 Linq 后,字典Dictionary排序变得十分简单,用一句类似 sql 数据库查询语句即可搞定:不过,.net 2.0 排序要稍微麻烦一点,为便于使用,将总 ...

  4. 转:python dict按照value 排序

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

  5. (转)Python 字典排序

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

  6. C# 键值对排序

    static void Main(string[] args) { SortedList sl = new SortedList(); sl.Add("001", "Za ...

  7. python dict sorted 排序

    https://www.cnblogs.com/linyawen/archive/2012/03/15/2398292.html 我们知道Python的内置dictionary数据类型是无序的,通过k ...

  8. ResourceDictionary文件排序方法

    默认生成的ResourceDictionary文件是根据主键的hashcode排序生成的,如果想按主键排序生成是不可能的. 可以使用Xml的处理方法来生成ResourceDictionary文件. 1 ...

  9. C# - 集合类

    C#的集合类命名空间介绍: // 程序集 mscorlib.dll System.dll System.Core.dll // 命名空间 using System.Collections:集合的接口和 ...

随机推荐

  1. js this理解

    原文链接:http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html this是js语言的几个关键字,代表 ...

  2. Exit code from container executor initialization is : 24 ExitCodeException exitCode=24: Configuration file ../etc/hadoop/container-executor.cfg not found.

    /etc/hadoop/conf的软链接(/etc/hdfs/conf)不正确,应该是/etc/yarn/conf

  3. IDEA建立---- java web项目

    1.新建一个javaweb项目 2.给项目命名 3.建立完的项目结构大概是这样(在web 下新建 两个目录lib 和 classes) 4.找到project Structure---------&g ...

  4. 【OS】分页和分段

    在网上找到了一个比较形象的比喻   打个比方,比如说你去听课,带了一个纸质笔记本做笔记.笔记本有100张纸,课程有语文.数学.英语三门,对于这个笔记本的使用,为了便于以后复习方便,你可以有两种选择. ...

  5. js函数前面写上分号的原因

    说个之前先说,网站上传一些文件,考虑到性能问题,会用一些压缩软件来压缩代码(grunt,glup,webpack,etc..),这时候就可能出现一个问题.看下面代码 (function a(){... ...

  6. cocos2d-x 图片性能测试

    本文是原创文章,如需转载,请注明文章出处 本次测试使用的cocos2d-x版本是3.9,测试环境是XCode7自带的iphone5 一.JPG格式与PVR.CCZ格式对比 1.占用空间对比 a)不透明 ...

  7. 今天初步了解了informix的锁的概念

     今天初步了解了informix的锁的概念  2005-06-12 01:07:05 分类: IT生活 在load的时候,碰到好几次"-134 ISAM Error :no more loc ...

  8. CSS 日常问题总结

    1.关于文本多余部分用省略号代替: http://www.cnblogs.com/hellman/p/5755376.html

  9. 日期控件,layui

    <link rel="stylesheet" href="<%=path%>/layui/css/layui.css" type=" ...

  10. windows下安装MongoDB要注意的问题

    1.  errno:10061 由于目标计算机积极拒绝,无法连接. 解决方法:在mongoDB的bin目录下,打开命令行,输入: mongod --dbpath "c:\data\db&qu ...