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. java_easyui体系之DataGrid(1)[转]

    一:简介 以表格的形式展示数据.项目中式很常见的一个使用.table展示数据.牵扯到分页.上一页下一页.首页.尾页.翻页.选中展示的记录用于操作.总记录数等等.使用DataGrid很容易实现这一点. ...

  2. 根据ip获取用户地理位置

    各大网站都提供根据ip获取用户地理位置信息,这里以新浪的接口为例子 接口地址为:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js ...

  3. AspNetPager分页

    1.页面部分 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefi ...

  4. html 选择图片后马上展示出来

    document.getElementById('file4').onchange = function(evt) { // 如果浏览器不支持FileReader,则不处理 if (!window.F ...

  5. 手机抓包-fiddler

    如果app走的是http协议,不用root,只需要通过fiddler做代理,就可以抓到所有请求. 1. fiddler+手机wifi设置 安装fiddler,勾中 Fiddler Options -& ...

  6. 使用HTML5+CSS3制作圆角内发光按钮----示例

    <!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. jQuery.extend源码深层分析

    在网站的开发中,经常会自己写一些jQuery插件来方便使用,其中自然少不了一个关键的方法->jQuery.extend(),使用这个方法来扩展jQuery对象. 那么今天就来讲讲这个函数的实现原 ...

  8. realestate.cei.gov.cn

    using AnfleCrawler.Common; using System; using System.Collections.Concurrent; using System.Collectio ...

  9. 【LeetCode OJ】Convert Sorted List to Binary Search Tree

    Problem Link: http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ We design a ...

  10. Day18_集合第四天

    1.Map集合成员方法(掌握) 增加功能 V put(K key, V value) 当key在集合中不存在时,添加元素:当key在集合存在时候,替换元素 删除功能 void clear 清除所有键值 ...