DictionaryExtensions Class
Provides extension methods for Dictionary<TKey, TValue>.
public static class DictionaryExtensionsMethods
| Name | Description |
|---|---|
| GetOrAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, Func<TKey, TValue>) | Gets the value associated with the specified key or adds it using the factory function if it doesn't exist. |
| GetOrAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue) | Gets the value associated with the specified key or adds it if it doesn't exist. |
| TryUpdate<TKey, TValue>(Dictionary<TKey, TValue>, TKey, Func<TKey, TValue, TValue>) | Attempts to update the value associated with the specified key using the factory function. |
| TryUpdate<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue) | Attempts to update the value associated with the specified key. |
GetOrAdd overloads
GetOrAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, Func<TKey, TValue>)
DictionaryExtensions.csGets the value associated with the specified key or adds it using the factory function if it doesn't exist.
public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, Func<TKey, TValue> valueFactory) where TKey : notnullType parameters
TKeyTValue
Parameters
dictDictionary<TKey, TValue>keyTKeyvalueFactoryFunc<TKey, TValue>
Returns
TValue
Remarks
The key is only added once valueFactory has returned, so a factory that throws leaves the dictionary unchanged.
GetOrAdd<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue)
DictionaryExtensions.csGets the value associated with the specified key or adds it if it doesn't exist.
public static TValue GetOrAdd<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue value) where TKey : notnullTryUpdate overloads
TryUpdate<TKey, TValue>(Dictionary<TKey, TValue>, TKey, Func<TKey, TValue, TValue>)
DictionaryExtensions.csAttempts to update the value associated with the specified key using the factory function.
public static bool TryUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, Func<TKey, TValue, TValue> valueFactory) where TKey : notnullType parameters
TKeyTValue
Parameters
dictDictionary<TKey, TValue>keyTKeyvalueFactoryFunc<TKey, TValue, TValue>
Returns
TryUpdate<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue)
DictionaryExtensions.csAttempts to update the value associated with the specified key.
public static bool TryUpdate<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue value) where TKey : notnull