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

      

  • 相关阅读:
    Tree Recovery解题报告
    bjtuOJ1019 Robot
    bjtuOJ1137 蚂蚁爬杆
    栈的使用,rails
    重做catch the cow
    C#3.0新特性之匿名类型
    C#Lambda表达式的用法
    C#进程的使用方法详解
    C#进程管理启动和停止
    C#LINQ查询表达式用法
  • 原文地址:https://www.cnblogs.com/as3lib/p/6434165.html
Copyright © 2011-2022 走看看