使用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. iOS 工程功能实现之好用的第三方

    1.http://www.cocoachina.com/ios/20140224/7868.html  (一个天气App案例) LBBlurredImage是一个继承自UIImageView,轻而易举 ...

  2. mysql mybatis-generator plugin 分页

    generator.xml配置如下: plugin必须紧跟context,否则会报错 <?xml version="1.0" encoding="UTF-8&quo ...

  3. event事件对象和clientX,clientY

    一.event : 事件对象 , 当一个事件发生的时候,和当前这个对象发生的这个事件有关的一些详细的信息都会被临时保存到一个指定地方-event对象,供我们在需要的调用.如:飞机-黑匣子 事件对象必须 ...

  4. .net mvc利用NPOI导入导出excel

    1.导出Excel :首先引用NPOI包(Action一定要用FileResult) /// <summary> /// 批量导出需要导出的列表 /// </summary> ...

  5. String or binary data would be truncated 解决办法

    原因: 一般出现这个问题是因为数据库中的某个字段的长度小,而插入数据大 解决: 找到相应字段,修改表结构,使表字段大小相同或大于要插入的数据

  6. webstorm自动编译typescript

    http://bbs.egret.com/thread-1752-1-1.html http://bbs.egret.com/thread-1912-1-1.html

  7. 当父级是body时,子元素设置position:absolute;定位是根据body还是html呢?

    position:absolute 元素相对最近的 position 为 absolute / relative / fixed 的祖先元素(包含块)定位,如果没有这样的祖先元素,则以初始包含块进行定 ...

  8. Laravel RuntimeException inEncrypter.php line 43: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths

    php artisan key:generate 运行上面代码即可解决

  9. php学习函数

    1defined和define区别 2.dirname(__FILE__) 3.set_include_path 4.get_include_path 5.realpath() 6.require_p ...

  10. 开发一个简单的python计算器

    要求: 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4* ...