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

      

  • 相关阅读:
    k邻近
    C语言实现pwd—关于linux文件系统
    Linux多线程
    有关临时表
    毕设—线程池thread_pool(草)
    3-26
    3-25
    3-22
    关于中国神华
    3-20
  • 原文地址:https://www.cnblogs.com/as3lib/p/6434165.html
Copyright © 2011-2022 走看看