Dictionary的基本用法
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的基本用法相关推荐
- (转)C#2.0泛型--Dictionary,List用法
C#2.0泛型--Dictionary,List用法 泛型是 C#2.0 语言和公共语言运行库 (CLR) 中的一个新功能.泛型将类型参数的概念引入 .NET Framework,类型参数使得设计如下 ...
- python字典和集合对象可以进行索引操作吗_python 集合(set)和字典(dictionary)的用法解析...
Table of Contents generated with DocToc ditctaionary and set hash 介绍 hash是计算机中非常常见一种查找的手法,它可以支持常数时间的 ...
- Dictionary集合
2019独角兽企业重金招聘Python工程师标准>>> Dictionary<string, string>是一个泛型集合,他本身有集合的功能有时候可以把它看成数组, 他 ...
- C#中使用Dictionary实现Map数据结构——VC编程网
转载自: http://blog.51cto.com/psnx168 在VC中使用过CMap以及在Java中使用过Map的朋友应该很熟悉,使用Map可以方便实现基于键值对数据的处理,在C#中,你就需要 ...
- c#_Dictionary集合
方法/步骤 要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) Dictionary的描述 1.从一组键(Key ...
- Codecademy网学习Python第六天
先回顾一下昨天的内容,本文前半部分主要是关于for loop的内容,loop是循环的意思.前文有关于for的一般用法,for item in list. 本次将其拓展为在Dictionary里的用法, ...
- 从学龄前开始解读FFMPEG代码 之 AVDictionary结构体以及av_dict_set()相关函数
从学龄前开始解读FFMPEG代码 之 AVDictionary结构体以及av_dict_set相关函数 开始AVDictionary以及相关函数学习前想说的一些话 从AVDictionary开始 av ...
- mathtype分隔符显示与隐藏
显示mathtype分隔符 在mathtype进行公式自动编号时,通过添加章节分隔符进行编号的章节化(类似第三章的公式对应编号3-1,3-2). mathtype的分隔符默认是隐藏的,选择[MathT ...
- vim 高级应用 原文地址 http://www.2maomao.com/blog/wp-content/uploads/vim_tips.txt
最佳vim技巧 ---------------------------------------- # 信息来源 ---------------------------------------- www ...
最新文章
- GStreamer跨平台多媒体框架
- c#如何读取相机手机的拍摄时间
- c++ 遍历list_数据结构之图的遍历,一篇文章get全部考点
- 重写AgileEAS.NET SOA 中间件平台账号密码的加密算法
- 英特尔携手ATT和爱立信进行DIRECTV NOW流媒体直播服务的5G试验
- Python基础6:深浅拷贝
- 1.Spring——七大主要模块
- liunx apache 的安装
- Cisco IP Phone 功能亮相(4)
- 使用eeupdate修改机器网卡mac地址
- ModifyStyle()
- 研华工控机维修IPC-610MB-L主机电脑维修
- java解析json字符串数据
- ios healthkit_如何使用Swift从iOS的HealthKit中读写Mindful Minutes
- 教你如何批量下载QQ相册或是手机相册里原照片
- 2021年东南大学软件学院电子信息考研信息
- ES根据日期查询数据
- 《IT项目经理成长手记》读后有所思
- Mac 中composer的安装
- 如何右键菜单添加命令提示符_在右键菜单顶部添加过滤器命令
热门文章
- Matlab自制Colorbar(二)
- Python文件读写缓冲区和文件读写操作实例
- C#——基于C#+asp.net+sqlserver的网上书店系统设计与实现(程序源码)
- 高职信息安全比赛攻防思路_2019全国职业院校技能大赛高职组信息安全管理与评估赛项在汉举行...
- 最新!芯片行业有哪些知名企业?
- Java使用阿里大于发送短信通知和短信验证码
- BUUCTF Crypto
- 基于Win32的多线程客户/服务器通信
- 一个简单答题系统的设计与实现(一)
- 数字化转型,企业为什么要转型?如何转型?