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 的几种遍历方法,排序的更多相关文章

  1. Dictionary 的几种遍历方法

    Dictionary 的几种遍历方法 Dictionary<string, int>dic = newDictionary<string, int>(); 方法1 foreac ...

  2. Dictionary的几种遍历方法

    Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("d", 1) ...

  3. C# Dictionary 的几种遍历方法

    Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("d", 1) ...

  4. javase-常用三种遍历方法

    javase-常用三种遍历方法 import java.util.ArrayList; import java.util.Iterator; import java.util.List; public ...

  5. Java中Map的三种遍历方法

    Map的三种遍历方法: 1. 使用keySet遍历,while循环: 2. 使用entrySet遍历,while循环: 3. 使用for循环遍历.   告诉您们一个小秘密: (下↓面是测试代码,最爱看 ...

  6. Jquery中each的三种遍历方法

    Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...

  7. java 完全二叉树的构建与四种遍历方法

    本来就是基础知识,不能丢的太干净,今天竟然花了那么长的时间才写出来,记一下. 有如下的一颗完全二叉树: 先序遍历结果应该为:1  2  4  5  3  6  7 中序遍历结果应该为:4  2  5 ...

  8. HashMap的四种遍历方法,及效率比较(简单明了)

    https://yq.aliyun.com/ziliao/210955 public static void main(String[] args) { HashMap<Integer, Str ...

  9. Java List /ArrayList 三种遍历方法

    java list三种遍历方法性能比较http://www.cnblogs.com/riskyer/p/3320357.html JAVA LIST 遍历http://blog.csdn.net/lo ...

随机推荐

  1. ue4 character 物理测试

    charactor里 CapsuleComponnet Mesh CharacterMovement 3个组件里有有物理开关 目前看Mesh的Simulate Physics+Enable Gravi ...

  2. BZOJ 1069: [SCOI2007]最大土地面积(旋转卡壳)

    题目链接~ 1069: [SCOI2007]最大土地面积 思路很简单,极角排序求完凸包后,在凸包上枚举对角线,然后两边分别来两个点旋转卡壳一下,搞定! 不过计算几何的题目就是这样,程序中间的处理还是比 ...

  3. Vue实例生命周期+vueRoter

    Vue实例生命周期 vue生命周期之beforeCreate 实例创建之前除标签外,所有的vue需要的数据,事件都不存在 vue生命周期之created 实例创建之后,data和事件已经被解析到,el ...

  4. Angular2.0的学习(一)

    第一节课 1.Angular程序架构 2.搭建Angular开发环境 3.开发在线竞拍程序Auction的第一个版本

  5. python HTTP 状态码

    404 Not Found 在HTTP请求的路径无法匹配任何RequestHandler类相对应的模式时返回404(Not Found)响应码. 400 Bad Request 如果你调用了一个没有默 ...

  6. nginx的基本操作

    启动 nginx -c /etc/nginx/nginx.conf停止nginx -s stop nginx -s quit pkill -9 nginx重载nginx -s reload文件检测ng ...

  7. Jquery3

    动画 动画动画效果一:show(时间),hide(时间)说明:时间的单位为毫秒方法toggle(时间):使用动画切换显示与隐藏动画效果二:slideDown(时间),slideUp(时间)切换:sli ...

  8. 关于Kendo UI 开发教程

    Kendo UI 开发教程 jQuery UI 是一套 JavaScript 函式库,提供抽象化.可自订主题的 GUI 控制项与动画效果.基于 jQuery JavaScript 函式库,可用来建构互 ...

  9. JavaScprit30-6 学习笔记

    今天学习的是  仿即时搜索诗句效果 第一个问题: fetch() Fetch API  提供了一个 JavaScript接口,用于访问和操纵HTTP管道的部分,例如请求和响应.它还提供了一个全局 fe ...

  10. JavaScript中三种字符串连接方式及其性能比较

    参考地址: https://www.cnblogs.com/programs/p/5554742.html 工作中经常会碰到要把2个或多个字符串连接成一个字符串的问题,在JS中处理这类问题一般有三种方 ...