Namespace: Assorted.Utils.Collections
Assembly: Assorted.Utils (Assorted.Utils.dll) version 1.1.0.0
Gets the value that is associated with a specified key.
Overload | Description |
---|---|
GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue>, TKey, TValue) | Gets the value that is associated with a specified key. Returns a specific value if the key is not found. |
GetValueOrDefault<TValue>(this IDictionary<string, object>, string, TValue) | Gets the value of a specified type that is associated with a specified key. Returns a specific value if the key is not found. |
Gets the value that is associated with a specified key. Returns a specific value if the key is not found.
public static TValue GetValueOrDefault<TKey, TValue>(
this IReadOnlyDictionary<TKey, TValue> source,
TKey key,
TValue defaultValue = null
)
TKey
The type of keys in the dictionary.
TValue
The type of values in the dictionary.
source
: IReadOnlyDictionary<TKey, TValue>
The source dictionary.
key
: TKey
The key to locate.
defaultValue
: TValue
If the key is not found, this value will be returned.
TValue
defaultValue
if the value associated with the specified key
is not found; otherwise, the found value.
Exception | Description |
---|---|
System.ArgumentNullException | source is null . |
Gets the value of a specified type that is associated with a specified key. Returns a specific value if the key is not found.
public static TValue GetValueOrDefault<TValue>(
this IDictionary<string, object> source,
string key,
TValue defaultValue = null
)
TValue
The type of values in the dictionary.
source
: IDictionary<string, object>
The source dictionary.
key
: string
The key to locate.
defaultValue
: TValue
If the key is not found, this value will be returned.
TValue
defaultValue
if the value associated with the specified key
is not found; otherwise, the found value.
Exception | Description |
---|---|
System.ArgumentNullException | source is null . |
System.InvalidCastException | The specified key is found, but its associated value is not type of TValue . |
This document is generated by DG.