线程安全集合 ConcurrentDictionary<TKey, TValue> 类
2014-06-04 15:34
483 查看
ConcurrentDictionary<TKey, TValue> 类
【表示可由多个线程同时访问的键/值对的线程安全集合。】
支持 .NET Framework 4.0 及以上。
示例代码:
谢谢浏览!
【表示可由多个线程同时访问的键/值对的线程安全集合。】
支持 .NET Framework 4.0 及以上。
示例代码:
class CD_Ctor { // Demonstrates: // ConcurrentDictionary<TKey, TValue> ctor(concurrencyLevel, initialCapacity) // ConcurrentDictionary<TKey, TValue>[TKey] static void Main() { // We know how many items we want to insert into the ConcurrentDictionary. // So set the initial capacity to some prime number above that, to ensure that // the ConcurrentDictionary does not need to be resized while initializing it. int NUMITEMS = 64; int initialCapacity = 101; // The higher the concurrencyLevel, the higher the theoretical number of operations // that could be performed concurrently on the ConcurrentDictionary. However, global // operations like resizing the dictionary take longer as the concurrencyLevel rises. // For the purposes of this example, we'll compromise at numCores * 2. int numProcs = Environment.ProcessorCount; int concurrencyLevel = numProcs * 2; // Construct the dictionary with the desired concurrencyLevel and initialCapacity ConcurrentDictionary<int, int> cd = new ConcurrentDictionary<int, int>(concurrencyLevel, initialCapacity); // Initialize the dictionary for (int i = 0; i < NUMITEMS; i++) cd[i] = i * i; Console.WriteLine("The square of 23 is {0} (should be {1})", cd[23], 23 * 23); } }
谢谢浏览!
相关文章推荐
- .net源码分析 - ConcurrentDictionary<TKey, TValue>
- SortedDictionary<TKey, TValue> 类 表示根据键进行排序的键/值对的集合。
- ConcurrentDictionary<TKey, TValue>的AddOrUpdate方法
- Dictionary<TKey, TValue> 散列集合
- .net源码分析 - ConcurrentDictionary<TKey, TValue>
- 都说ConcurrentDictionary<TKey, TValue>有陷阱
- .Net集合类的研究-有序集合(二)-SortedDictionary<TKey,TValue>
- Mvvm combobox绑定Dictionary<Key,Value>问题
- C# - IOrderedDictionary<TKey, TValue> Implementation
- c# 扩展方法奇思妙用基础篇五:Dictionary<TKey, TValue> 扩展
- Dictionary<TKey, TValue> 进行where的枚举遍历
- c# 扩展方法奇思妙用基础篇五:Dictionary<TKey, TValue> 扩展
- Dictionary、List<KeyValuePair<i>>的组合使用
- C#学习常用类(1003)---ConcurrentDictionary<TKey,TValue>
- .net源码分析 – Dictionary<TKey, TValue>
- 1.C#泛型-泛型集合Dictionary<Key,Value>
- C# Dictionary的用法 KeyValuePair<TKey, TValue> 结构
- C#学习常用类(3000)---ConcurrentDictionary<TKey,TValue>类
- C# - OrderedDictionary<TKey, TValue> Implementation
- HashTable与Dictionary<TKey, TValue>