ConcurrentDictionary<TKey,TValue> 构造函数

定义

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例。

重载

ConcurrentDictionary<TKey,TValue>()

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认并发级别,具有默认的初始容量,并使用键类型的默认比较器。

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

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定 IEnumerable<T>复制的元素,具有默认并发级别,具有默认的初始容量,并使用键类型的默认比较器。

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

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认并发级别和容量,并使用指定的 IEqualityComparer<T>

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

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定 IEnumerable 复制的元素具有默认并发级别,具有默认的初始容量,并使用指定的 IEqualityComparer<T>

ConcurrentDictionary<TKey,TValue>(Int32, Int32)

初始化为空的 ConcurrentDictionary<TKey,TValue> 类的新实例,具有指定的并发级别和容量,并使用键类型的默认比较器。

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

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定 IEnumerable复制的元素,并使用指定的 IEqualityComparer<T>

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

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有指定的并发级别,具有指定的初始容量,并使用指定的 IEqualityComparer<T>

ConcurrentDictionary<TKey,TValue>()

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认并发级别,具有默认的初始容量,并使用键类型的默认比较器。

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

注解

默认并发级别等于 CPU 数。 并发级别越高,并发写入操作就越多,而不会造成干扰和阻塞。 较高的并发级别值还会导致需要所有锁的操作(例如表大小调整、ToArrayCount)变得更加昂贵。 默认容量(DEFAULT_CAPACITY),表示初始存储桶数,是小字典的大小与构造大型字典时调整大小之间的权衡。 此外,容量不应被小质数分割。 默认容量为 31。

另请参阅

适用于

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

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定 IEnumerable<T>复制的元素,具有默认并发级别,具有默认的初始容量,并使用键类型的默认比较器。

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>>

其元素复制到新 ConcurrentDictionary<TKey,TValue>IEnumerable<T>

例外

collection 或其任何密钥 null

collection 包含一个或多个重复键。

另请参阅

适用于

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

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有默认并发级别和容量,并使用指定的 IEqualityComparer<T>

public:
 ConcurrentDictionary(System::Collections::Generic::IEqualityComparer<TKey> ^ comparer);
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>

比较键时要使用的相等比较实现。

例外

comparer null

另请参阅

适用于

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

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定 IEnumerable 复制的元素具有默认并发级别,具有默认的初始容量,并使用指定的 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);
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>>

其元素复制到新 ConcurrentDictionary<TKey,TValue>IEnumerable<T>

comparer
IEqualityComparer<TKey>

比较键时要使用的 IEqualityComparer<T> 实现。

例外

collectioncomparernull

另请参阅

适用于

ConcurrentDictionary<TKey,TValue>(Int32, Int32)

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化为空的 ConcurrentDictionary<TKey,TValue> 类的新实例,具有指定的并发级别和容量,并使用键类型的默认比较器。

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

估计将同时更新 ConcurrentDictionary<TKey,TValue> 的线程数,或仅在 .NET 8+ 中更新,-1 以指示默认并发级别。

capacity
Int32

ConcurrentDictionary<TKey,TValue> 可以包含的初始元素数。

例外

concurrencyLevel 小于 1。

-或-

capacity 小于 0。

另请参阅

适用于

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

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例包含从指定 IEnumerable复制的元素,并使用指定的 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);
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

估计将同时更新 ConcurrentDictionary<TKey,TValue> 的线程数,或仅在 .NET 8+ 中更新,-1 以指示默认并发级别。

collection
IEnumerable<KeyValuePair<TKey,TValue>>

其元素复制到新 ConcurrentDictionary<TKey,TValue>IEnumerable<T>

comparer
IEqualityComparer<TKey>

比较键时要使用的 IEqualityComparer<T> 实现。

例外

collectioncomparernull

concurrencyLevel 小于 1。

collection 包含一个或多个重复键。

另请参阅

适用于

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

Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs
Source:
ConcurrentDictionary.cs

初始化 ConcurrentDictionary<TKey,TValue> 类的新实例,该实例为空,具有指定的并发级别,具有指定的初始容量,并使用指定的 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);
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

估计将同时更新 ConcurrentDictionary<TKey,TValue> 的线程数,或仅在 .NET 8+ 中更新,-1 以指示默认并发级别。

capacity
Int32

ConcurrentDictionary<TKey,TValue> 可以包含的初始元素数。

comparer
IEqualityComparer<TKey>

比较键时要使用的 IEqualityComparer<T> 实现。

例外

comparer null

concurrencyLevelcapacity 小于 1。

另请参阅

适用于