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]]);

}

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(); //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. Windows“神器”收集贴

    本文本来是刚开始发现autohotkey时比较兴奋,收集了几个autohotkey的介绍页面.最近又发现了win下多桌面的神器virtuawin,心想干脆在把本帖改成专门收集win下神器的帖子吧.如果 ...

  2. 优化ubuntu桌面

    ---恢复内容开始--- 此博主写的很全 http://blog.csdn.net/terence1212/article/details/52270210 使用安装Unity Tweak Tool ...

  3. 将excel2003文档文件转换为excel2007格式

    在sharepoint 2010 中,excel2007或excel 2010文档格式,支持web app 应用,能够在浏览器在线打开,查看,但excel 2003格式的文档只能用office客户端打 ...

  4. surface实例-小球弹起事例

    ball.java package com.example.sufacedemo; import android.graphics.Bitmap; import android.graphics.Bi ...

  5. android中图片的三级缓存cache策略(内存/文件/网络)

    实现图片缓存也不难,需要有相应的cache策略.这里我采用 内存-文件-网络 三层cache机制,其中内存缓存包括强引用缓存和软引用缓存(SoftReference),其实网络不算cache,这里姑且 ...

  6. Javascript DOM基础(二) childNodes、children

    childNodes知识点: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Typ ...

  7. Objective C运行时(runtime)技术的几个要点总结

    前言:          Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...

  8. php冒泡排序

    <?php $arr = array(1,4,2,9,0,10,12,3,7); foreach($arr as $val) { echo $val."--"; } echo ...

  9. maven遇到的问题

    1.Missing artifact net.sf.json-lib:json-lib:jar:2.4:compile pom.xml原内容: <dependency> <group ...

  10. HTML5实战——svg学习

    百度百科: SVG可缩放矢量图形(Scalable Vector Graphics)是基于可扩展标记语言(XML),用于描述二维矢量图形的一种图形格式.SVG是W3C制定的一种新的二维矢量图形格式,也 ...