<PackageReference Include="System.Collections.Concurrent" Version="4.0.11-beta-23409" />

System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>

public class ConcurrentDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>
Represents a thread-safe collection of key/value pairs that can be accessed by multiple threads concurrently.
public int Count { get; }

Gets the number of key/value pairs contained in the ConcurrentDictionary<T, U>.

public bool IsEmpty { get; }

Gets a value that indicates whether the ConcurrentDictionary<T, U> is empty.

public TValue this[TKey key] { get; set; }

Gets or sets the value associated with the specified key.

public ICollection<TKey> Keys { get; }

Gets a collection containing the keys in the Dictionary<T, U>.

public ICollection<TValue> Values { get; }

Gets a collection that contains the values in the Dictionary<T, U>.

Initializes a new instance of the ConcurrentDictionary<T, U> 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(int concurrencyLevel, int capacity)

Initializes a new instance of the ConcurrentDictionary<T, U> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the key type.

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

Initializes a new instance of the ConcurrentDictionary<T, U> 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(IEqualityComparer<TKey> comparer)

Initializes a new instance of the ConcurrentDictionary<T, U> class that is empty, has the default concurrency level and capacity, and uses the specified IEqualityComparer<T>.

public ConcurrentDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)

Initializes a new instance of the ConcurrentDictionary<T, U> 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(int concurrencyLevel, IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)

Initializes a new instance of the ConcurrentDictionary<T, U> class that contains elements copied from the specified IEnumerable, and uses the specified IEqualityComparer<T>.

public ConcurrentDictionary(int concurrencyLevel, int capacity, IEqualityComparer<TKey> comparer)

Initializes a new instance of the ConcurrentDictionary<T, U> class that is empty, has the specified concurrency level, has the specified initial capacity, and uses the specified IEqualityComparer<T>.

public TValue AddOrUpdate(TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)

Uses the specified functions to add a key/value pair to the ConcurrentDictionary<T, U> if the key does not already exist, or to update a key/value pair in the ConcurrentDictionary<T, U> if the key already exists.

public TValue AddOrUpdate(TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)

Adds a key/value pair to the ConcurrentDictionary<T, U> if the key does not already exist, or updates a key/value pair in the ConcurrentDictionary<T, U> by using the specified function if the key already exists.

public void Clear()

Removes all keys and values from the ConcurrentDictionary<T, U>.

public bool ContainsKey(TKey key)

Determines whether the ConcurrentDictionary<T, U> contains the specified key.

public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()

Returns an enumerator that iterates through the ConcurrentDictionary<T, U>.

public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)

Adds a key/value pair to the ConcurrentDictionary<T, U> by using the specified function, if the key does not already exist.

public TValue GetOrAdd(TKey key, TValue value)

Adds a key/value pair to the ConcurrentDictionary<T, U> if the key does not already exist.

public KeyValuePair<TKey, TValue>[] ToArray()

Copies the key and value pairs stored in the ConcurrentDictionary<T, U> to a new array.

public bool TryAdd(TKey key, TValue value)

Attempts to add the specified key and value to the ConcurrentDictionary<T, U>.

public bool TryGetValue(TKey key, out TValue value)

Attempts to get the value associated with the specified key from the ConcurrentDictionary<T, U>.

public bool TryRemove(TKey key, out TValue value)

Attempts to remove and return the value that has the specified key from the ConcurrentDictionary<T, U>.

public bool TryUpdate(TKey key, TValue newValue, TValue comparisonValue)

Compares the existing value for the specified key with a specified value, and if they are equal, updates the key with a third value.