星空网 > 软件开发 > ASP.net

C#遍历Dictionary

C#遍历Dictionary方法

Dictionary<string, int> d = new Dictionary<string, int>();foreach (KeyValuePair<string, int> pair in d){   Console.WriteLine("{0}, {1}",        pair.Key,        pair.Value);    }Dictionary<string, int> list = new Dictionary<string, int>();      //C#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]]);      }IDictionary dictionary = new Hashtable();foreach (DictionaryEntry entry in dictionary){  Object key = entry.Key;  Object val = entry.Value;}/* 何问起 hovertree.com */

推荐:http://www.cnblogs.com/roucheng/p/3521864.html




原标题:C#遍历Dictionary

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

海运到东南亚:https://www.goluckyvip.com/tag/99287.html
东南亚海运爆仓:https://www.goluckyvip.com/tag/99288.html
Joom佣金:https://www.goluckyvip.com/tag/9929.html
东南亚海运航线图:https://www.goluckyvip.com/tag/99290.html
到东南亚海运运费:https://www.goluckyvip.com/tag/99291.html
东南亚海运费用:https://www.goluckyvip.com/tag/99292.html
2024北京庞各庄镇梨花节开幕时间是几号?:https://www.vstour.cn/a/365179.html
深圳西乡三月三北帝庙会的千岁盆菜多少钱:https://www.vstour.cn/a/365180.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流