Dictionary和Hashtable的一些异同
Dictionary和Hashtable 区别:
Dictionary |
Hashtable |
| 支持范型 | 不支持 |
| 需要自己做线程同步 | 通过调用 Synchronized() 方法可以获得线程安全的类型 |
| 枚举类型是KeyValuePair | 枚举类型是DictionaryEntry |
| .Net 2.0开始有 | .Net 1.0开始有 |
| System.Collections.Generic命名空间下 | System.Collections命名空间下 |
| 获取同一个不存在的key时抛出异常 | 获取同一个不存在的key时返回NULL |
| 值类型不需要装箱/拆箱,可能会更快些 | 值类型value types需要装箱/拆箱boxing/unboxing |
相同点:
内部都是hashtable实现,通过key访问数据比较快
都需要不可变的,唯一的key
key都需要有自己的GetHashCode()方法
其他类似的.Net 集合(用于替代Dictionary和备选项)Hashtable的
ConcurrentDictionary - 用于多并发、线程安全的字典
HybridDictionary - System.Collections.Specialized命名空间下,优化了性能(在集合较小时,使用 ListDictionary 来实现 IDictionary,然后当集合变大时,切换到Hashtable。)
OrderedDictionary - System.Collections.Specialized命名空间下,值可以通过数字索引访问,因为元素添加的时候已经被指定位置了。public void Insert(int index, object key, object value);
SortedDictionary - 元素插入时自动的被排序
StringDictionary - System.Collections.Specialized命名空间下,将键和值强类型化为字符串而不是对象,对做相应的优化。
Dictionary和Hashtable的一些异同的更多相关文章
- 【算法】272-每周一练 之 数据结构与算法(Dictionary 和 HashTable)
这是第五周的练习题,上周忘记发啦,这周是复习 Dictionary 和 HashTable. 下面是之前分享的链接: [算法]200-每周一练 之 数据结构与算法(Stack) [算法]213-每周一 ...
- 每周一练 之 数据结构与算法(Dictionary 和 HashTable)
这是第五周的练习题,上周忘记发啦,这周是复习 Dictionary 和 HashTable. 下面是之前分享的链接: 1.每周一练 之 数据结构与算法(Stack) 2.每周一练 之 数据结构与算法( ...
- C#中Dictionary,Hashtable,List的比较及分析
一. Dictionary与Hashtable Dictionary与Hashtable都是.Net Framework中的字典类,能够根据键快速查找值 二者的特性大体上是相同的,有时可以把Dicti ...
- [ASP.NET] Dictionary 和 Hashtable 区别
Dictionary和Hashtable 是两个比较常用的表示键/值的集合,两者在实际使用过程中有何区别呢? 具体区别如下: 1. Hashtable不支持泛型,而Dictionary支持泛型. 2. ...
- Java集合——HashMap、HashTable以及ConCurrentHashMap异同比较
0. 前言 HashMap和HashTable的区别一种比较简单的回答是: (1)HashMap是非线程安全的,HashTable是线程安全的. (2)HashMap的键和值都允许有null存在,而H ...
- Dictionary,hashtable, stl:map有什么异同?
相同点:字典和map都是泛型,而hashtable不是泛型. 不同点:三者算法都不相同 Hashtable,看名字能想到,它是采用传统的哈希算法:探测散列算法,而字典则采用的是散列拉链算法,效率较高, ...
- dictionary 和 hashtable 区别
区别:1,Dictionary支持泛型,而Hashtable不支持. 2,Dictionary没有装填因子(Load Facto)概念,当容量不够时才扩容(扩容跟Hashtable一样,也是两倍于当前 ...
- List、dictionary、hashtable、ArrayList集合
集合的引用命名空间在 system.Collections下 1.为什么引入集合 因为数组长度是固定的,为了建立一个动态的"数组",所以引入了集合. 2.为什么引入ArrayLis ...
- javascript实现集合Set、字典Dictionary、HashTable
集合是由一组无序且唯一(即不能重复)的项组成的.这个数据结构使用了与有限集合相同的数学概念,但应用在计算机科学的数据结构中. function Set() { this.items = {}; } S ...
随机推荐
- Easyui 小脚本
function addTab(subtitle, url, icon) { if (!$('#tabs').tabs('exists', subtitle)) { $('#tabs').tabs(' ...
- sql server 跨数据库插入数据
创建服务器的连接,创建好后可以存在服务器上,可以在不同位置重复使用,和系统函数类似 exec sp_addlinkedserver 'RemoteServer', '', 'SQLOLEDB ', ' ...
- c++ 一些随笔
1. A region of source code where any use of the unqualified name (that is, as a plain identifier) re ...
- git 命令记录
git log 配置 git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -% ...
- IIS发布问题汇总
1.未能加载文件或程序集“System.Data.SQLite” 在IIS界面选择应用程序池->选择所使用的.net 版本->高级设置->将"使用32位应用程序" ...
- C# char 和string之间转换
har数组要转换成string可没想象的那么容易.需要使用到System.Text.StringBuilder!实例如下: char[] temp={a,b,c};System.Text.String ...
- hmtl弹出框样式
@model Web.Manager.Models.SendMessage @{ ViewBag.Title = "消息发布"; Layout = null;} <link ...
- VS 远程调试之 “The visual studio remote debugger does not support this edition of windows”
The error message "The visual studio remote debugger does not support this edition of windows&q ...
- robocopy 命令小结
robocopy "C:\dira" "J:\dira" /E /COPYALL /XJ /XD "C:\dira\dir1" " ...
- su with hyphen and without - su带横杠和不带横杠
The difference between "-" and "no hyphen" is that the latter keeps your existin ...