ConcurrentDictionary<TKey,TValue> ConcurrentDictionary<TKey,TValue> ConcurrentDictionary<TKey,TValue> ConcurrentDictionary<TKey,TValue> Constructors

定义

重载

ConcurrentDictionary<TKey,TValue>() ConcurrentDictionary<TKey,TValue>() ConcurrentDictionary<TKey,TValue>()

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认的并发级别和默认的初始容量,并为键类型使用默认比较器。 Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IEnumerable<T> 中复制的元素,具有默认的并发级别和默认的初始容量,并为键类型使用默认比较器。 Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that contains elements copied from the specified IEnumerable<T>, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认的并发级别和容量,并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the default concurrency level and capacity, and uses the specified IEqualityComparer<T>.

ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素,具有默认的并发级别和默认的初始容量,并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that contains elements copied from the specified IEnumerable has the default concurrency level, has the default initial capacity, and uses the specified IEqualityComparer<T>.

ConcurrentDictionary<TKey,TValue>(Int32, Int32) ConcurrentDictionary<TKey,TValue>(Int32, Int32) ConcurrentDictionary<TKey,TValue>(Int32, Int32) ConcurrentDictionary<TKey,TValue>(Int32, Int32)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有指定的并发级别和容量,并为键类型使用默认比较器。 Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the key type.

ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that contains elements copied from the specified IEnumerable, and uses the specified IEqualityComparer<T>.

ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有指定的并发级别和指定的初始容量,并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the specified concurrency level, has the specified initial capacity, and uses the specified IEqualityComparer<T>.

ConcurrentDictionary<TKey,TValue>() ConcurrentDictionary<TKey,TValue>() ConcurrentDictionary<TKey,TValue>()

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认的并发级别和默认的初始容量,并为键类型使用默认比较器。 Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

public:
 ConcurrentDictionary();
public ConcurrentDictionary ();
Public Sub New ()

注解

默认的并发级别等于 Cpu 数。The default concurrency level is equal to the number of CPUs. 并发级别越高,更多的并发写入操作可以发生而不会相互干扰和阻塞。The higher the concurrency level is, the more concurrent write operations can take place without interference and blocking. 较高的并发级别值也会导致需要所有锁的操作 (例如,表重设大小,ToArrayCount) 以变得更高。Higher concurrency level values also cause operations that require all locks (for example, table resizing, ToArray and Count) to become more expensive. 构造大型字典时,默认的容量 (DEFAULT_CAPACITY),它表示初始存储桶数,是字典的非常小的大小和调整大小活动数之间进行权衡。The default capacity (DEFAULT_CAPACITY), which represents the initial number of buckets, is a trade-off between the size of a very small dictionary and the number of resizes when constructing a large dictionary. 此外,容量不应为整除小的质数。Also, the capacity should not be divisible by a small prime number. 默认的容量为 31。The default capacity is 31.

另请参阅

ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IEnumerable<T> 中复制的元素,具有默认的并发级别和默认的初始容量,并为键类型使用默认比较器。 Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that contains elements copied from the specified IEnumerable<T>, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.

public:
 ConcurrentDictionary(System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>> ^ collection);
public ConcurrentDictionary (System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>> collection);
new System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value> : seq<System.Collections.Generic.KeyValuePair<'Key, 'Value>> -> System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value>
Public Sub New (collection As IEnumerable(Of KeyValuePair(Of TKey, TValue)))
参数
collection
IEnumerable<KeyValuePair<TKey,TValue>>

IEnumerable<T>,它的元素被复制到新 ConcurrentDictionary<TKey,TValue> The IEnumerable<T> whose elements are copied to the new ConcurrentDictionary<TKey,TValue>.

异常

collection 或其中的任一键为 null collection or any of its keys is null.

collection 包含一个或多个重复键。 collection contains one or more duplicate keys.

另请参阅

ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认的并发级别和容量,并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the default concurrency level and capacity, and uses the specified IEqualityComparer<T>.

public:
 ConcurrentDictionary(System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public ConcurrentDictionary (System.Collections.Generic.IEqualityComparer<TKey> comparer);
new System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value> : System.Collections.Generic.IEqualityComparer<'Key> -> System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value>
Public Sub New (comparer As IEqualityComparer(Of TKey))
参数
comparer
IEqualityComparer<TKey>

在对键进行比较时使用的相等比较实现。 The equality comparison implementation to use when comparing keys.

异常
另请参阅

ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素,具有默认的并发级别和默认的初始容量,并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that contains elements copied from the specified IEnumerable has the default concurrency level, has the default initial capacity, and uses the specified IEqualityComparer<T>.

public:
 ConcurrentDictionary(System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>> ^ collection, System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public ConcurrentDictionary (System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>> collection, System.Collections.Generic.IEqualityComparer<TKey> comparer);
new System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value> : seq<System.Collections.Generic.KeyValuePair<'Key, 'Value>> * System.Collections.Generic.IEqualityComparer<'Key> -> System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value>
Public Sub New (collection As IEnumerable(Of KeyValuePair(Of TKey, TValue)), comparer As IEqualityComparer(Of TKey))
参数
collection
IEnumerable<KeyValuePair<TKey,TValue>>

IEnumerable<T>,它的元素被复制到新 ConcurrentDictionary<TKey,TValue> The IEnumerable<T> whose elements are copied to the new ConcurrentDictionary<TKey,TValue>.

comparer
IEqualityComparer<TKey>

在对键进行比较时使用的 IEqualityComparer<T> 实现。 The IEqualityComparer<T> implementation to use when comparing keys.

异常

collectioncomparernull collection or comparer is null.

另请参阅

ConcurrentDictionary<TKey,TValue>(Int32, Int32) ConcurrentDictionary<TKey,TValue>(Int32, Int32) ConcurrentDictionary<TKey,TValue>(Int32, Int32) ConcurrentDictionary<TKey,TValue>(Int32, Int32)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有指定的并发级别和容量,并为键类型使用默认比较器。 Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the key type.

public:
 ConcurrentDictionary(int concurrencyLevel, int capacity);
public ConcurrentDictionary (int concurrencyLevel, int capacity);
new System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value> : int * int -> System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value>
Public Sub New (concurrencyLevel As Integer, capacity As Integer)
参数
concurrencyLevel
Int32 Int32 Int32 Int32

将同时更新 ConcurrentDictionary<TKey,TValue> 的线程的估计数量。 The estimated number of threads that will update the ConcurrentDictionary<TKey,TValue> concurrently.

capacity
Int32 Int32 Int32 Int32

ConcurrentDictionary<TKey,TValue> 可包含的初始元素数。 The initial number of elements that the ConcurrentDictionary<TKey,TValue> can contain.

异常

concurrencyLevel 小于 1。 concurrencyLevel is less than 1. -or- capacity 小于 0。 capacity is less than 0.

另请参阅

ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定的 IEnumerable 中复制的元素并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that contains elements copied from the specified IEnumerable, and uses the specified IEqualityComparer<T>.

public:
 ConcurrentDictionary(int concurrencyLevel, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<TKey, TValue>> ^ collection, System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public ConcurrentDictionary (int concurrencyLevel, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>> collection, System.Collections.Generic.IEqualityComparer<TKey> comparer);
new System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value> : int * seq<System.Collections.Generic.KeyValuePair<'Key, 'Value>> * System.Collections.Generic.IEqualityComparer<'Key> -> System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value>
Public Sub New (concurrencyLevel As Integer, collection As IEnumerable(Of KeyValuePair(Of TKey, TValue)), comparer As IEqualityComparer(Of TKey))
参数
concurrencyLevel
Int32 Int32 Int32 Int32

将同时更新 ConcurrentDictionary<TKey,TValue> 的线程的估计数量。 The estimated number of threads that will update the ConcurrentDictionary<TKey,TValue> concurrently.

collection
IEnumerable<KeyValuePair<TKey,TValue>>

IEnumerable<T>,它的元素被复制到新 ConcurrentDictionary<TKey,TValue> The IEnumerable<T> whose elements are copied to the new ConcurrentDictionary<TKey,TValue>.

comparer
IEqualityComparer<TKey>

在对键进行比较时使用的 IEqualityComparer<T> 实现。 The IEqualityComparer<T> implementation to use when comparing keys.

异常

collectioncomparernull collection or comparer is null.

collection 包含一个或多个重复键。 collection contains one or more duplicate keys.

另请参阅

ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>) ConcurrentDictionary<TKey,TValue>(Int32, Int32, IEqualityComparer<TKey>)

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有指定的并发级别和指定的初始容量,并使用指定的 IEqualityComparer<T> Initializes a new instance of the ConcurrentDictionary<TKey,TValue> class that is empty, has the specified concurrency level, has the specified initial capacity, and uses the specified IEqualityComparer<T>.

public:
 ConcurrentDictionary(int concurrencyLevel, int capacity, System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
public ConcurrentDictionary (int concurrencyLevel, int capacity, System.Collections.Generic.IEqualityComparer<TKey> comparer);
new System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value> : int * int * System.Collections.Generic.IEqualityComparer<'Key> -> System.Collections.Concurrent.ConcurrentDictionary<'Key, 'Value>
Public Sub New (concurrencyLevel As Integer, capacity As Integer, comparer As IEqualityComparer(Of TKey))
参数
concurrencyLevel
Int32 Int32 Int32 Int32

将同时更新 ConcurrentDictionary<TKey,TValue> 的线程的估计数量。 The estimated number of threads that will update the ConcurrentDictionary<TKey,TValue> concurrently.

capacity
Int32 Int32 Int32 Int32

ConcurrentDictionary<TKey,TValue> 可包含的初始元素数。 The initial number of elements that the ConcurrentDictionary<TKey,TValue> can contain.

comparer
IEqualityComparer<TKey>

在对键进行比较时使用的 IEqualityComparer<T> 实现。 The IEqualityComparer<T> implementation to use when comparing keys.

异常

concurrencyLevelcapacity 小于 1。 concurrencyLevel or capacity is less than 1.

另请参阅

适用于