惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V2EX - 技术
V2EX - 技术
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
GbyAI
GbyAI
The Cloudflare Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
IT之家
IT之家
H
Help Net Security
宝玉的分享
宝玉的分享
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
博客园_首页
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
The Hacker News
The Hacker News
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
P
Palo Alto Networks Blog
博客园 - 聂微东
罗磊的独立博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
U
Unit 42
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyberwarzone
Cyberwarzone
G
Google Developers Blog
C
Cybersecurity and Infrastructure Security Agency CISA
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Tailwind CSS Blog
雷峰网
雷峰网
C
Cisco Blogs

博客园 - 朱小能

linq to sql中的自动缓存(对象跟踪) javascript 调用webservice 的几种方法 修改域名映射IP地址 SQL 语句,类型转换 hyper-v 网络连接 VS2010 定位文件在solution中的位置 oracle连接字符串配置 spool的简单使用 open数据库Timeout expired 错误 文件的还原与备份 - 朱小能 - 博客园 ASCII码,对应e.KeyChar C# 调用计算器,日历 - 朱小能 - 博客园 Excel 如何由一个文本算术公式得到一个结果 Word、Excel中输入当前日期及时间的快捷键 c# ToString 格式化数字 - 朱小能 GridView绑定 获取access中表的相关信息 Filelog - 朱小能 - 博客园 List<T> 排序 - 朱小能 - 博客园
C#对Dictionary的按Value排序
朱小能 · 2013-10-06 · via 博客园 - 朱小能

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