zoukankan      html  css  js  c++  java
  • C#中dictionary的使用

    在C#中,Dictionary提供快速的基于键值的元素查找。

    他的结构是:Dictionary<[key], [value]> ,当有很多元素的时候可以使用它。使用前,必须声明它的键类型和值类型,如下。

    Dictionary<string, string> dictionary= new Dictionary<string, string>();

    添加数据

    if (!pList.ContainsKey("Item1"))            
      pList.Add("Item1", "ZheJiang");

    删除数据

    myDictionary.Remove(key);

    根据Key获取VALUE

    String value=dictionary[Key];

    遍历数据

     foreach (var node in dictionary)
      {
      //...
      }

    遍历key

    foreach (var key in dictionary.Keys)
        {
            Console.WriteLine("Output Key: {0}", key);
        }

    遍历value

    foreach (String value in dictionary.Values)
        {
            Console.WriteLine("Output Value: {0}", value);
        }


  • 相关阅读:
    小程序 scroll-view 中文字不换行问题
    模块
    网络编程
    元类
    day24
    day23
    day22
    day21
    day18
    day17
  • 原文地址:https://www.cnblogs.com/wxwx/p/5776233.html
Copyright © 2011-2022 走看看