zoukankan      html  css  js  c++  java
  • C# Dictionary 的几种遍历方法

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

    //3.0以上版本

               foreach(variteminlist)

                {

                   Console.WriteLine(item.Key + item.Value);

                }

               //KeyValuePair<T,K>

               foreach(KeyValuePair<string,int> kvinlist)

                {

                   Console.WriteLine(kv.Key + kv.Value);

                }

               //过键的集合取

               foreach(stringkeyinlist.Keys)

                {

                   Console.WriteLine(key + list[key]);

                }

               //直接取值

               foreach(intvalinlist.Values)

                {

                   Console.WriteLine(val);

                }

                //非要采用for的方法也可

               List<string> test =newList<string>(list.Keys);

     

               for(inti = 0; i < list.Count; i++)

                {

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

                }

     

    内容源自 http://wutaichi.blog.sohu.com/190336531.html

  • 相关阅读:
    推荐随笔
    搭建http服务
    python之numpy和pandas
    eclipse项目打包
    keras安装
    eclipse设置快速提示符
    linux常用命令
    Webpack3 从入门到放弃
    【ES6】Generator+Promise异步编程
    【Vue】删除数组元素,导致剩余元素被重新渲染
  • 原文地址:https://www.cnblogs.com/yf2011/p/3081840.html
Copyright © 2011-2022 走看看