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

                }

  • 相关阅读:
    (C#)asp_net调试错误解决方法收集(1)
    asp.net调试技巧
    asp。Net 页面传值
    viewState详解
    Session,ViewState用法
    asp.net中通过form表单submit提交到后台的实例
    C#读写xml文件
    Asp.Net前台调用后台变量
    3. mybatis # 与 $ 的区别
    IDEA 中 使用 git(Git)
  • 原文地址:https://www.cnblogs.com/seeworld/p/6815597.html
Copyright © 2011-2022 走看看