Class DictionaryExtensions
- Namespace
- Utils.Collections
- Assembly
- Utils.dll
Provides thread-safe helper methods for working with Dictionary<TKey, TValue> instances.
public static class DictionaryExtensions
- Inheritance
-
DictionaryExtensions
- Inherited Members
Methods
GetOrAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, Func<TValue>)
Retrieves the value associated with key or adds a
new value created by func in a thread-safe manner.
public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, Func<TValue> func) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>The dictionary to operate on.
keyTKeyKey of the element to retrieve.
funcFunc<TValue>Factory used to create the value when absent.
Returns
- TValue
The existing or newly added value.
Type Parameters
TKeyKey type.
TValueValue type.
GetOrAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue)
Retrieves the value associated with key or adds the
provided value in a thread-safe manner.
public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>The dictionary to operate on.
keyTKeyKey of the element to retrieve.
valueTValueValue to add if the key is not present.
Returns
- TValue
The existing or newly added value.
Type Parameters
TKeyKey type.
TValueValue type.
TryUpdate<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue)
Attempts to update an existing entry with the specified
value in a thread-safe manner.
public static bool TryUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
Parameters
dictionaryDictionary<TKey, TValue>The dictionary to update.
keyTKeyKey of the element to update.
valueTValueThe new value.
Returns
Type Parameters
TKeyKey type.
TValueValue type.