Dictionary<string, int> list = new Dictionary<string, int>();

list.Add("d", 1);

//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 = 0; i < list.Count; i++)

{

Console.WriteLine(test[i] + list[test[i]]);

}

Dictionary的几种遍历方法的更多相关文章

  1. Dictionary 的几种遍历方法

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

  2. C# 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(); //3.0以上版本 fore ...

  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. 技海拾贝 - Java

    1. Java中的多线程 http://blog.csdn.net/luoweifu/article/details/46673975 Java中继承thread类与实现Runnable接口的区别 h ...

  2. Flask 的扩展

    1. Flask-Script,为Flask程序提供了一个命令行解析器: (venv) $ pip install flask-script 2. Bootstrap(http://getbootst ...

  3. 数论 UVA 10791

    这道题目是关于满足同意最小公倍数的所有数对中两数之和的最小值. 题目大意是给你一个数n,要求你求出在所有以n为最小公倍数的数对中两数之和的最小值. 方法:将n进行质因数分解,再将所有分解出的质因子加起 ...

  4. applicationCache对象

    applicationCache对象代表了本地缓存,可以在js中进行一些操作.可以用它来通知用户本地缓存中已经被更新,也允许用户手工更新本地缓存.applicationCache.addEventLi ...

  5. 通过sougou输入法,解决卡在Setup Wizard(小绿人)界面

    本人使用海信EG900手机(安卓2.3.5,已root),为了使用google的服务,先后手动复制和CWM recovery刷入google服务包(gapps-gb-20110828-signed.z ...

  6. JAVA hashmap知识整理

    HashMap和Hashtable的比较是Java面试中的常见问题,用来考验程序员是否能够正确使用集合类以及是否可以随机应变使用多种思路解决问题.HashMap的工作原理.ArrayList与Vect ...

  7. pyspider 简单应用之快速问医生药品抓取(一)

    网址:http://yp.120ask.com/search/-0-0--0-0-0-0.html from pyspider.libs.base_handler import * class Han ...

  8. Mac 使用 SSH 免密连接服务器

    1.生成 SSH 秘钥 ssh-keygen -t rsa  生成的密钥对 id_rsa 和 id_rsa.pub,默认存储在 ~/.ssh 目录,其中没有后缀的是私有,有后缀 .pub 的为公钥.生 ...

  9. var关键字获取数据类型

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  10. Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04 配置参考文献 以及 常见编译问题总结

    Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04  配置参考文献 ---- Wang Xiao Warning: Please make sure the cud ...