Method SafeGet
SafeGet<TKey, TValue>(IDictionary<TKey, TValue>, TKey)
Safely gets a value from a dictionary, or the default if the key does not exist.
public static TValue? SafeGet<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
Parameters
dictionaryIDictionary<TKey, TValue>The dictionary to query.
keyTKeyThe key to look up.
Returns
- TValue
The value for the key if present; otherwise the default value for
TValue.
Type Parameters
TKeyThe dictionary key type.
TValueThe dictionary value type.