KeyValuePairTKey, TValue是DictionaryEntry的泛型版本
如同Dictionary<TKey, TValue>是HashTable的泛型版本一样,KeyValuePair<TKey, TValue>是DictionaryEntry的泛型版本。
Dictionary与HashTable内部是基于hash算法的,而SortedDictionary和SortedList是基于Red Black Tree(红黑树)的。
DictionaryEntry:
Hashtable openWith = new Hashtable();
// Add some elements to the hash table. There are no
// duplicate keys, but some of the values are duplicates.
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe");
// When you use foreach to enumerate hash table elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine();
foreach (DictionaryEntry de in openWith)
{
Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
KeyValuePair<TKey, TValue>:
Dictionary<string, string> openWith =
new Dictionary<string, string>();
// Add some elements to the dictionary. There are no
// duplicate keys, but some of the values are duplicates.
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe");
foreach( KeyValuePair<string, string> kvp in myDictionary )
{
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
}
OO与面向接口:
KeyValuePairTKey, TValue是DictionaryEntry的泛型版本相关推荐
- keyvaluepair_C# KeyValuePairTKey,TValue的用法【转】 .
KeyValuePair可以这样实例化 KeyValuePair mcmillan = new KeyValuePair("McMillan", 99); 取值 Console.W ...
- KeyvaluePair 与 DictionaryEntry
如同Dictionary<TKey, TValue>是HashTable的泛型版本一样,KeyValuePair<TKey, TValue>是DictionaryEntry的泛 ...
- 使用泛型创建只读集合
本系列文章翻译O'Reilly 出版的<C# Cookbook>一书中的片段,仅供学习交流使用 4.9 使用泛型创建只读集合 问题 您希望类中的一个集合里的信息可以被外界访问,但不希望用户 ...
- C#中的集合、哈希表、泛型集合、字典
集合ArrayList 集合:集合可以看做是数组,可以将其看成"长度可变,具有很多方法的数组".使用ArrayList,首先需要导入命名空间using.system.collect ...
- 4.9 利用对应的泛型替换Hashtable[转]
摘要:<C#3.0cookbook中文版><C#3.0cookbook中文版>本书侧重于解决C#程序员在开发应用程序时遇到的各类问题,并以此组织全书内容.这些解决方案称为秘 ...
- [C#泛型系列文章]
第一部分:O'Reilly 出版的<C# Cookbook>泛型部分翻译 第一回:理解泛型 第二回:获取泛型类型和使用相应的泛型版本替换ArrayList 第三回:使用相应的泛型版本替换S ...
- 细细品味C#——泛型系列专题
什么是泛型? 泛型是程序设计语言的一种特性.允许程序员在强类型程序设计语言中编写 体验泛型代码时定义一些可变部份,那些部份在使用前必须作出指明.各种程序设计语言和其编译器.运行环境对泛型的支持均不一 ...
- C#精髓【月儿原创】第三讲 C#泛型有什么好处
说明:准备出一个系列,所谓精髓讲C#语言要点.这个系列没有先后顺序,不过尽量做到精.可能会不断增删整理,本系列最原始出处是csdn博客,谢谢关注. C#精髓 第三讲 C#泛型有什么好处 作者:清清月儿 ...
- 用了这么多年的 Java 泛型,你对它到底有多了解?|原创
作为一个 Java 程序员,日常编程早就离不开泛型.泛型自从 JDK1.5 引进之后,真的非常提高生产力.一个简单的泛型 T,寥寥几行代码, 就可以让我们在使用过程中动态替换成任何想要的类型,再也不用 ...
最新文章
- 地平线:全球估值第一的AI芯片初创公司诞生!
- c语言数组怎么环形阵列,C语言 用于大阵列的无复制线程安全环形缓冲区
- (十三) 构建dubbo分布式平台-dubbo管控台安装
- .NET MVC-去掉验证
- linux c 崩溃调试方法
- ElasticSearch-hadoop saveToEs源码分析
- android电话拨号器
- 后台开发经典书籍--大话设计模式
- 华为故事,李一男,任正非
- Spring MVC绑定,无设置器
- 1090. Highest Price in Supply Chain (25)
- 那是财务自由的声音!寒武纪上市造就一批85后亿万富翁
- linux查看tomcat安装路径
- window7 右键菜单显示-》在此处打开命令窗口
- Allegro 拼板
- 写学术论文的一些感想
- 轻松调整C盘分区大小
- 【科研技巧】PPT如何导出1000dpi的图片
- ldap协议端口号_什么是LDAP协议端口号? 比较LDAP端口389和636
- Kotlin写界面时诸多控件的点击事件