C#对Dictionary的按Value排序
使用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排序的更多相关文章
- c# Dictionary的遍历和排序
c# Dictionary的遍历和排序 c#遍历的两种方式 for和foreach for: 需要指定首位数据.末尾数据.数据长度: for遍历语句中可以改变数据的值: 遍历规则可以自定义,灵活性较高 ...
- c# Dictionary的遍历和排序(转)
c#遍历的两种方式 for和foreach for: 需要指定首位数据.末尾数据.数据长度: for遍历语句中可以改变数据的值: 遍历规则可以自定义,灵活性较高 foreach: 需要实现ienume ...
- C#对 Dictionary进行排序 转
C# .net 3.5 以上的版本引入 Linq 后,字典Dictionary排序变得十分简单,用一句类似 sql 数据库查询语句即可搞定:不过,.net 2.0 排序要稍微麻烦一点,为便于使用,将总 ...
- 转:python dict按照value 排序
我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...
- (转)Python 字典排序
我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...
- C# 键值对排序
static void Main(string[] args) { SortedList sl = new SortedList(); sl.Add("001", "Za ...
- python dict sorted 排序
https://www.cnblogs.com/linyawen/archive/2012/03/15/2398292.html 我们知道Python的内置dictionary数据类型是无序的,通过k ...
- ResourceDictionary文件排序方法
默认生成的ResourceDictionary文件是根据主键的hashcode排序生成的,如果想按主键排序生成是不可能的. 可以使用Xml的处理方法来生成ResourceDictionary文件. 1 ...
- C# - 集合类
C#的集合类命名空间介绍: // 程序集 mscorlib.dll System.dll System.Core.dll // 命名空间 using System.Collections:集合的接口和 ...
随机推荐
- jdbcTemplate的Dao层封装
package com.easyrail.base.dao; import java.io.Serializable; import java.lang.reflect.Field; import j ...
- mysql复制一列到另一列
mysql复制一列到另一列 UPDATE 表名 SET B列名=A列名 需求:把一个表某个字段内容复制到另一张表的某个字段. 实现sql语句1: 复制代码代码如下: UPDATE file_man ...
- 多线程学习中的Tips
ParameterizedThreadStart委托与ThreadStart委托,非常相似,但ParameterizedThreadStart委托是面向带参数方法的.注意ParameterizedTh ...
- Android 开发如何选择轮子(转)
一个项目的开发,我们不可能一切从0做起,如果真是这样,那同样要哭瞎.因此,善于借用已经做好的 "车轮" 非常重要,如: 网络访问框架:OKHttp.retrofit.android ...
- Ajax聊天
结构: index.html <!DOCTYPE html> <html> <head> <title>index.html</title> ...
- 解决VS2012编写JQuery代码不能智能提示的问题(其他js库的代码提示设置估计类似)
VS默认设置下编写jQuery代码是这样的: 解决办法: 1.在项目的"管理NuGet程序包"中安装JQuery: 2.打开:工具 -> 选项 -> 文本编辑器 -&g ...
- Guava----Function
1. Function接口,提供两个方法: apply方法: 可以自定义自己想实现的功能 @Nullable T apply(@Nullable F input); 1. 实例: import com ...
- jquery 跨域访问问题 转
http://zld406504302.iteye.com/blog/1677937 服务器,jsp <%@ page language="java" contentType ...
- Jenkins 命令
Jenkins 服务集群环境的启动命令 #必须在root下启动 sh /home/jenkins/tomcat/bin/startup.sh dubbo服务注册中心 zookeeper启动命令 /we ...
- LR手动关联新手总结
最近学习LoadRunner的时候深刻体会:新手入门真心不容易啊 今天一直在纠结LoadRunner的手动关联问题,之前刚开始看书的时候就看到了,不过当时想先放放,后面来细细研究, 今天看的时候在网上 ...