GetValueOrDefault Method
Definition
- Namespace
- Cuemon.Extensions.Collections.Generic
- Assemblies
- Cuemon.Extensions.Collections.Generic.dll
GetValueOrDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, Func<TValue>)
Gets the value associated with the specified key or a default value through defaultProvider when the key does not exists in the dictionary.
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TValue> defaultProvider)
Parameters
dictionaryIDictionary<TKey, TValue>The IDictionary<TKey, TValue> to extend.
keyTKeyThe key of the value to get.
defaultProviderFunc<TValue>The function delegate that will provide a default value when the
keydoes not exists in thedictionary.
Returns
- TValue
Either the value associated with the specified
keyor a default value throughdefaultProviderwhen the key does not exists.
Type Parameters
TKeyThe type of the keys in the
dictionary.TValueThe type of the values in the
dictionary.
Exceptions
- ArgumentNullException
dictionarycannot be null -or-keycannot be null -or-defaultProvidercannot be null.