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


  • 相关阅读:
    python调用ggsci.exe程序
    confluence安装
    nginx优化
    ELKstack搭建
    zabbix 安装
    python requests
    小程序消息推送
    shell
    rar 解压
    ubuntu 安装部分设置U盘启动系统安装盘操作
  • 原文地址:https://www.cnblogs.com/wxwx/p/5776233.html
Copyright © 2011-2022 走看看