Dictionary<TKey,TValue> 与 Hashtable区别
存储数据类型区别
特定类型(不包括 Object)的 Dictionary
这是因为 Hashtable 的元素属于 Object 类型;因此,装箱和取消装箱通常发生在存储或检索值类型时。
可能有多个线程同时访问该集合时,应使用 ConcurrentDictionary
拓展:线程安全数据类型
带Concurrent 关键的数据类型
具体如下
类型 | 描述 |
---|---|
BlockingCollection |
为实现 IProducerConsumerCollection |
ConcurrentDictionary |
键值对字典的线程安全实现。 |
ConcurrentQueue |
FIFO(先进先出)队列的线程安全实现。 |
ConcurrentStack |
LIFO(后进先出)堆栈的线程安全实现。 |
ConcurrentBag |
无序元素集合的线程安全实现。 |
IProducerConsumerCollection |
类型必须实现以在 BlockingCollection 中使用的接口。 |
https://docs.microsoft.com/zh-cn/dotnet/standard/collections/thread-safe/