zoukankan      html  css  js  c++  java
  • c# Dictionary字典类如何使用

        Dictionary<string, string> openWith = new Dictionary<string, string>();
                //添加元素
                openWith.Add("txt", "notepad.exe");
                openWith.Add("bmp", "paint.exe");
                openWith.Add("dib", "paint.exe");
                openWith.Add("rtf", "wordpad.exe");
    
                Console.WriteLine("For key = "rtf", value = {0}.", openWith["rtf"]);
                //更改值
                openWith["rtf"] = "winword.exe";
                Console.WriteLine("For key = "rtf", value = {0}.", openWith["rtf"]);
    
                //遍历key
                foreach (string key in openWith.Keys)
                {
                    Console.WriteLine("Key = {0}", key);
                }
                //遍历value
                foreach (string value in openWith.Values)
                {
                    Console.WriteLine("value = {0}", value);
                }
                //遍历字典
                foreach (KeyValuePair<string, string> kvp in openWith)
                {
                    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                }
                Console.WriteLine("===============");
                //删除元素
                openWith.Remove("rtf");
                //遍历字典
                foreach (KeyValuePair<string, string> kvp in openWith)
                {
                    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
                }
    

      

  • 相关阅读:
    Nginx配置文件详解
    Mycat概述
    日志切割之Logrotate
    js数组(二)
    js数组(一)
    sass颜色
    scss
    HTML5新属性
    HTML5新元素
    Bootstrap
  • 原文地址:https://www.cnblogs.com/as3lib/p/6434165.html
Copyright © 2011-2022 走看看