1.创建泛型哈希表,然后加入元素

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

2.遍历key

    foreach (string key in openWith.Keys){Console.WriteLine("Key = {0}", key);}
3.遍历valueforeach (string value in openWith.Values){Console.WriteLine("value = {0}", value);}```
4.遍历value, Second Method```csharp
Dictionary<string, string>.ValueCollection valueColl = openWith.Values;foreach (string s in valueColl){Console.WriteLine("Second Method, Value = {0}", s);}

5.遍历字典

foreach (KeyValuePair<string, string> kvp in openWith){Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);}

6.添加存在的sql语句元素

try{openWith.Add("txt", "winword.exe");}catch (ArgumentException){Console.WriteLine("An element with Key = \"txt\" already exists.");}

7.删除元素

openWith.Remove("doc");if (!openWith.ContainsKey("doc")){Console.WriteLine("Key \"doc\" is not found.");}
8.判断键存在if (openWith.ContainsKey("bmp")) // True {Console.WriteLine("An element with Key = \"bmp\" exists.");}

9.参数为其它c#教程
类型

Dictionary<int, string[]> OtherType = new Dictionary<int, string[]>();OtherType.Add(1, "1,11,111".Split(','));OtherType.Add(2, "2,22,222".Split(','));Console.WriteLine(OtherType[1][2]);

Dictionary的基本用法相关推荐

  1. (转)C#2.0泛型--Dictionary,List用法

    C#2.0泛型--Dictionary,List用法 泛型是 C#2.0 语言和公共语言运行库 (CLR) 中的一个新功能.泛型将类型参数的概念引入 .NET Framework,类型参数使得设计如下 ...

  2. python字典和集合对象可以进行索引操作吗_python 集合(set)和字典(dictionary)的用法解析...

    Table of Contents generated with DocToc ditctaionary and set hash 介绍 hash是计算机中非常常见一种查找的手法,它可以支持常数时间的 ...

  3. Dictionary集合

    2019独角兽企业重金招聘Python工程师标准>>> Dictionary<string, string>是一个泛型集合,他本身有集合的功能有时候可以把它看成数组, 他 ...

  4. C#中使用Dictionary实现Map数据结构——VC编程网

    转载自: http://blog.51cto.com/psnx168 在VC中使用过CMap以及在Java中使用过Map的朋友应该很熟悉,使用Map可以方便实现基于键值对数据的处理,在C#中,你就需要 ...

  5. c#_Dictionary集合

    方法/步骤 要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) Dictionary的描述 1.从一组键(Key ...

  6. Codecademy网学习Python第六天

    先回顾一下昨天的内容,本文前半部分主要是关于for loop的内容,loop是循环的意思.前文有关于for的一般用法,for item in list. 本次将其拓展为在Dictionary里的用法, ...

  7. 从学龄前开始解读FFMPEG代码 之 AVDictionary结构体以及av_dict_set()相关函数

    从学龄前开始解读FFMPEG代码 之 AVDictionary结构体以及av_dict_set相关函数 开始AVDictionary以及相关函数学习前想说的一些话 从AVDictionary开始 av ...

  8. mathtype分隔符显示与隐藏

    显示mathtype分隔符 在mathtype进行公式自动编号时,通过添加章节分隔符进行编号的章节化(类似第三章的公式对应编号3-1,3-2). mathtype的分隔符默认是隐藏的,选择[MathT ...

  9. vim 高级应用 原文地址 http://www.2maomao.com/blog/wp-content/uploads/vim_tips.txt

    最佳vim技巧 ---------------------------------------- # 信息来源 ---------------------------------------- www ...

最新文章

  1. GStreamer跨平台多媒体框架
  2. c#如何读取相机手机的拍摄时间
  3. c++ 遍历list_数据结构之图的遍历,一篇文章get全部考点
  4. 重写AgileEAS.NET SOA 中间件平台账号密码的加密算法
  5. 英特尔携手ATT和爱立信进行DIRECTV NOW流媒体直播服务的5G试验
  6. Python基础6:深浅拷贝
  7. 1.Spring——七大主要模块
  8. liunx apache 的安装
  9. Cisco IP Phone 功能亮相(4)
  10. 使用eeupdate修改机器网卡mac地址
  11. ModifyStyle()
  12. 研华工控机维修IPC-610MB-L主机电脑维修
  13. java解析json字符串数据
  14. ios healthkit_如何使用Swift从iOS的HealthKit中读写Mindful Minutes
  15. 教你如何批量下载QQ相册或是手机相册里原照片
  16. 2021年东南大学软件学院电子信息考研信息
  17. ES根据日期查询数据
  18. 《IT项目经理成长手记》读后有所思
  19. Mac 中composer的安装
  20. 如何右键菜单添加命令提示符_在右键菜单顶部添加过滤器命令

热门文章

  1. Matlab自制Colorbar(二)
  2. Python文件读写缓冲区和文件读写操作实例
  3. C#——基于C#+asp.net+sqlserver的网上书店系统设计与实现(程序源码)
  4. 高职信息安全比赛攻防思路_2019全国职业院校技能大赛高职组信息安全管理与评估赛项在汉举行...
  5. 最新!芯片行业有哪些知名企业?
  6. Java使用阿里大于发送短信通知和短信验证码
  7. BUUCTF Crypto
  8. 基于Win32的多线程客户/服务器通信
  9. 一个简单答题系统的设计与实现(一)
  10. 数字化转型,企业为什么要转型?如何转型?