使用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. Predicate接口和Consumer接口

    Predicate和Consumer接口是集合操作中常用到的俩个接口: 1.Predicate public interface Predicate<T>{ boolean test(T ...

  2. Tomcat7.0安装配置

    很久没有通过博客对学习所得进行记录了. 现在将使用Tomcat的一些经验和心得写到这里,作为记录和备忘.如果有朋友看到,也请不吝赐教. 首先,我个人使用的是apache-tomcat-7.0.27你可 ...

  3. OneSQL助力永辉超市大卖特卖

    数据库集群查询达到10w/s,更新操作5k/s,正常! 应用并发连接达到历史高峰4倍,正常! 业务平稳运行,正常! 永辉微店527大促,圆满成功!这标志着平民软件数据库工程师.accenture咨询实 ...

  4. Rdseed与SAC的安装

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  5. 搜集资料&安装环境

    开始入坑DSP,芯片是TI的TMS320C6678,硬件平台为TI官方的TMS320C6678L开发板. 官方给的资料有很多,各种用户手册.软件支持包,眼花缭乱.先尝试把开发环境搭起来,跑个Hello ...

  6. AX2012修改properties字体

    参考自http://www.ithao123.cn/wenku/list_310_2.html static void GD_Eric_ChangeUserinfoFont(Args _args){  ...

  7. 计时器js

    <html>    <head>    <meta http-equiv="Content-Type" content="text/html ...

  8. 删除Kafka的topic

    刚接触Kafka,开始认为删除一个topic只是运行一下Kafka-topic.sh的delete命令就行了,但是,事实却不是这样,会出现两种情况:(1) 如果topic没有使用过即没有传输过消息,可 ...

  9. TensorFlow之Varibale 使用方法

    ------------------------------------------- 转载请注明: 来自博客园 xiuyuxuanchen 地址:http://www.cnblogs.com/gre ...

  10. XObject.java 对象还没写完,希望电脑不会丢失。坏笑,早点见。

    /*面向对象强调的是对象, 面向过程强调的是功能行为,打开行为,关闭行为,执行行为,把多个行为封装成对象执行更强大的功能就是面向对象,是把多个函数, 多 个行为封装在一起,单一的函数执行对象的功能太困 ...