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

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

                }

  • 相关阅读:
    多层缓存、要素缓存
    ASP.NET提供三种主要形式的缓存
    cache、session、cookie的区别
    常用简写快速生成代码
    EF数据迁移
    源文件与模块生成时的文件不同,是否希望调试器使用它?
    强命名程序集组成与作用
    centOS docker运行Asp.net Core程序
    docker
    .net常用的代码生成工具
  • 原文地址:https://www.cnblogs.com/greyhh/p/4759700.html
Copyright © 2011-2022 走看看