C# Dictionary 的几种遍历方法,排序
Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("d", ); //3.0以上版本
foreach (var item in list)
{
Console.WriteLine(item.Key + item.Value);
}
//KeyValuePair<T,K>
foreach (KeyValuePair<string, int> kv in list)
{
Console.WriteLine(kv.Key + kv.Value);
}
//通过键的集合取
foreach (string key in list.Keys)
{
Console.WriteLine(key + list[key]);
}
//直接取值
foreach (int val in list.Values)
{
Console.WriteLine(val);
}
//非要采用for的方法也可
List<string> test = new List<string>(list.Keys); for (int i = ; i < list.Count; i++)
{
Console.WriteLine(test[i] + list[test[i]]);
}
Dictionary<string, string> dic1Asc = dic1.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
Dictionary<string, string> dic1desc = dic1.OrderByDescending(o => o.Key).ToDictionary(o => o.Key, p => p.Value); Dictionary<string, string> dic1Asc1
= (from d in dic1
orderby d.Key ascending
select d).ToDictionary(k => k.Key, v => v.Value);
Dictionary<string, string> dic1desc2
= (from d in dic1
orderby d.Key descending
select d).ToDictionary(k => k.Key, v => v.Value); List<string> list = new List<string>();
list.Add("aaa");
list.Add("ddd");
list.Add("bbb");
list.Add("ccc");
list.Add("bbb");
var ascList = list.OrderBy(o => o);
var descList = list.OrderByDescending(o => o); var ascList1 = (from l in list
orderby l ascending
select l).ToList();
var descList2 = (from l in list
orderby l descending
select l).ToList();
string str = "";
C# Dictionary 的几种遍历方法,排序的更多相关文章
- Dictionary 的几种遍历方法
Dictionary 的几种遍历方法 Dictionary<string, int>dic = newDictionary<string, int>(); 方法1 foreac ...
- Dictionary的几种遍历方法
Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("d", 1) ...
- C# Dictionary 的几种遍历方法
Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("d", 1) ...
- javase-常用三种遍历方法
javase-常用三种遍历方法 import java.util.ArrayList; import java.util.Iterator; import java.util.List; public ...
- Java中Map的三种遍历方法
Map的三种遍历方法: 1. 使用keySet遍历,while循环: 2. 使用entrySet遍历,while循环: 3. 使用for循环遍历. 告诉您们一个小秘密: (下↓面是测试代码,最爱看 ...
- Jquery中each的三种遍历方法
Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...
- java 完全二叉树的构建与四种遍历方法
本来就是基础知识,不能丢的太干净,今天竟然花了那么长的时间才写出来,记一下. 有如下的一颗完全二叉树: 先序遍历结果应该为:1 2 4 5 3 6 7 中序遍历结果应该为:4 2 5 ...
- HashMap的四种遍历方法,及效率比较(简单明了)
https://yq.aliyun.com/ziliao/210955 public static void main(String[] args) { HashMap<Integer, Str ...
- Java List /ArrayList 三种遍历方法
java list三种遍历方法性能比较http://www.cnblogs.com/riskyer/p/3320357.html JAVA LIST 遍历http://blog.csdn.net/lo ...
随机推荐
- vue父子组件路由传参的方式
一.get方式(url传参): 1.动态路由传参: 父组件: selectItem (item) { this.$router.push({ path: `/recommend/${item.id}` ...
- Unity开发Android应用优化指南(上)
http://forum.china.unity3d.com/thread-27037-1-2.html 如今越来越多的开发者使用Unity开发Android及iOS项目,开发过程中难免会遇到一些性能 ...
- c# new三种用法
前几天去家公司面试,有一道这样的题:写出c#中new关键字的三种用法,思前想后挖空心思也只想出了两种用法,回来查了下msdn,还真是有第三种用法:用于在泛型声明中约束可能用作类型参数的参数的类型,这是 ...
- 【转】生产环境:Nginx高可用方案
准备工作: 192.168.16.128 192.168.16.129 两条虚拟机.安装好 Nginx 安装Nginx 更新 yum 源文件: rpm -ivh http://nginx.org/pa ...
- 12.Python略有小成(生成器,推导式,内置函数,闭包)
Python(生成器,推导式,内置函数,闭包) 一.生成器初始 生成器的本质就是迭代器,python社区中认为生成器与迭代器是一种 生成器与迭代器的唯一区别,生成器是我们自己用python代码构建成的 ...
- LDAP第三天 MySQL+LDAP 安装
https://www.easysoft.com/applications/openldap/back-sql-odbc.html OpenLDAP 使用 SQLServer 和 Oracl ...
- Maven项目已启动但是报异常访问webapp下所有资源都404
- 在github上下载子文件夹(svn命令)
Q: 平时都是用git clone这个命令从github中克隆出完整的文件,但有时我们仅需要其中某个文件夹时,该如何下载? A: 可以使用svn命令来完成. 具体用法:(以视觉slam14讲的gith ...
- Linux中/etc/passwd 和 /etc/shadows 详解
linux操作系统上的用户如果需要登录主机,当其输入用户名和密码之后: 首先在/etc/passwd文件中查找是否有你的账号,如果没有无法登录,如果有的话将该用户的UID和GID读出来,此外将此用户的 ...
- 微服务架构 Steeltoe
.NET Core 微服务架构 Steeltoe 使用(基于 Spring Cloud) https://www.cnblogs.com/xishuai/p/steeltoe-and-spring-c ...