Summary
Gets the element with the specified key in the dictionary or the new value returned from the getValue callback.
If the shouldAdd callback returns
then the new value is added to the dictionary.
Syntax
public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dicionary, TKey key, Func<TKey, TValue> getValue, Func<TValue, bool> shouldAdd)
Type Parameters
Name |
Description |
TKey |
The type of keys in the dictionary. |
TValue |
The type of values in the dictionary. |
Parameters
Name |
Type |
Description |
dicionary |
IDictionary<TKey, TValue> |
The dictionary to get element from. |
key |
TKey |
The key of the element to get. |
getValue |
Func<TKey, TValue> |
The callback delegate to return value if element with specified key does not exist in the dicionary. |
shouldAdd |
Func<TValue, bool> |
The callback delegate to determine if the new value should be added to the dicionary. |
Return Value
Type |
Description |
TValue |
The element with the specified key, or the new value. |