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:集合的接口和 ...
随机推荐
- PBOC金融IC卡,卡片与终端交互的13个步骤,简介-第三组
七:终端风险管理-必选但包含可选步骤异常文件:终端检查应用主账号是否在异常文件列表(卡号黑名单)中.商户强制联机:商户可以将当前交易强制为联机处理.最低限额:控制交易当前交易金额或同一张卡片连续几笔交 ...
- CCNA网络基础(一)
现在我们使用这一个图来讲解网络的基础知识: 现在只看右边那个图,也就是两台主机和一个交换机 PC1 的配置是 IP 172.16.20.2/24 网关没有配 ...
- Python之路 day3 函数定义 *args及**kwargs
#!/usr/bin/env python # -*- coding:utf-8 -*- #Author:ersa import time # def logger(): # time_format ...
- 7 -- Spring的基本用法 -- 5...
7.5 Spring容器中的Bean 7.5.1 Bean的基本定义和Bean别名 <beans.../>元素是Spring配置文件的根元素,该元素可以指定如下属性: default-la ...
- webStorage和cookie的区别
共同点: 都是保存在浏览器端,且同源的 cookie有什么缺点? Cookie数量和长度的限制.每个domain最多只能有20条cookie,每个cookie长度不能超过4KB 安 ...
- 如何在本地电脑安装phpmyadmin及访问地址
因为要安装wordpress,上网查了下安装wordpress前要安装phpmyadmin,前提是要在自己本地电脑上安装APMSeverx虚拟主机才可以,在本地访问phpmyadmin页面.下面的步骤 ...
- 修改主机hostname
1 修改hostname配置文件 vi /etc/sysconfig/network中的HOSTNAME 2 修改完后,使用hostname命令验证,发现hostname还是原来的 退出shell重新 ...
- 05-String动手动脑问题及课后实验性问题总结
一.请运行以下实例代码StringPool.java,查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? (1)在Java中,内容相同的字符常量("Hello")只保存一 ...
- Tomcat部署web应用程序
对Tomcat部署web应用的方式总结,常见的有以下四种: 1.[替换ROOT目录] 最简单的一种方法,webapps目录下面ROOT文件夹的文件为你的文件,然后输入localhost:8080/首页 ...
- ubuntu 下非交互式执行远程shell命令
apt-get install sshpass sshpass -p **your_password** ssh -o StrictHostKeyChecking=no "root@$ip& ...