1. Dictionary<string, string> openWith = new Dictionary<string, string>();
  2. //添加元素
  3. openWith.Add("txt", "notepad.exe");
  4. openWith.Add("bmp", "paint.exe");
  5. openWith.Add("dib", "paint.exe");
  6. openWith.Add("rtf", "wordpad.exe");
  7.  
  8. Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
  9. //更改值
  10. openWith["rtf"] = "winword.exe";
  11. Console.WriteLine("For key = \"rtf\", value = {0}.", openWith["rtf"]);
  12.  
  13. //遍历key
  14. foreach (string key in openWith.Keys)
  15. {
  16. Console.WriteLine("Key = {0}", key);
  17. }
  18. //遍历value
  19. foreach (string value in openWith.Values)
  20. {
  21. Console.WriteLine("value = {0}", value);
  22. }
  23. //遍历字典
  24. foreach (KeyValuePair<string, string> kvp in openWith)
  25. {
  26. Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
  27. }
  28. Console.WriteLine("===============");
  29. //删除元素
  30. openWith.Remove("rtf");
  31. //遍历字典
  32. foreach (KeyValuePair<string, string> kvp in openWith)
  33. {
  34. Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
  35. }

  

c# Dictionary字典类如何使用的更多相关文章

  1. C#中的Dictionary字典类介绍

      Dictionary字典类介绍 必须包含名空间System.Collection.Generic    Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)    键必须是 ...

  2. (转)C#中的Dictionary字典类介绍

    关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/07/csharp-dictionar ...

  3. C# Dictionary字典类介绍

    说明    必须包含名空间System.Collection.Generic     Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)     键必须是唯一的,而值不需要唯 ...

  4. .net中的Dictionary字典类的使用方法

    //定义字典 Dictionary<string, string> d = new Dictionary<string, string>(); //添加字典的元素 ; i &l ...

  5. Dictionary字典类介绍

    说明     必须包含名空间System.Collection.Generic      Dictionary里面的每一个元素都是一个键值对(由二个元素组成:键和值)      键必须是唯一的,而值不 ...

  6. Dictionary字典类使用范例

    原文发布时间为:2009-11-04 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Web.UI.WebControls;using System ...

  7. C#中的Dictionary字典类常用方法介绍

    using System.Collections.Generic;//引用命名空间//Dictionary可以理解为散列集合 public class DictionaryTest { public ...

  8. C# Dictionary 字典

    C#中的Dictionary字典类介绍   关键字:C# Dictionary 字典 作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/ ...

  9. Swift字典类

    在Foundation框架中提供一种字典集合,它是由“键-值”对构成的集合.键集合不能重复,值集合没有特殊要求.键和值集合中的元素可以是任何对象,但是不能是nil.Foundation框架字典类也分为 ...

随机推荐

  1. mysql数据库基础知识和认识

    mysql 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail mysql -u root -ppassworduse mysql;insert into user(h ...

  2. Spring入门3.AOP编程

    Spring入门3.AOP编程 代码下载: 链接: http://pan.baidu.com/s/11mYEO 密码: x7wa 前言: 前面学习的知识是Spring在Java项目中的IoC或DJ,这 ...

  3. LeetCode OJ:N-Queens(N皇后问题)

    Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a d ...

  4. SpringInAction--Spring Web应用之SpringMvc 注解配置

    Spring MVC 是当前Web服务器中常用的结构,今天就来学习这相关的知识,首先上图——Spring请求的时候所经历的坎坷之路: (书上原话,算是解释..) 在请求离开浏览器时① ,会带有用户所请 ...

  5. Linux:更改hostname主机名

    更改hostname主机名 查看主机名 hostname 临时更改主机名 hostname youname 更改永久生效主机名 1)更改配置文件 vi /etc/sysconfig/network 2 ...

  6. ffmpeg jpeg图片播放失败之问题排查

    播放jpeg时,avformat_find_stream_info出现以下问题,排查: [jpeg_pipe @ 0x146a80] Could not find codec parameters f ...

  7. Gradle2.0用户指南翻译——第二章. 概述

    翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2 ...

  8. 基于EasyDSS流媒体服务器实现的直播流管理与鉴权的后台方案

    本文转自EasyDSS团队Marvin的博客:http://blog.csdn.net/marvin1311/article/details/73548929 最新版本的EasyDSS流媒体解决方案, ...

  9. $.ajax 的速度要快于 angular 里 $http (个别情况)

    $.ajax: $http:

  10. Split功能的思想实现

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...