Skip to content

Latest commit

 

History

History
111 lines (73 loc) · 3.86 KB

Assorted.Utils.Collections.DictionaryExtensions.GetValueOrDefault.md

File metadata and controls

111 lines (73 loc) · 3.86 KB

DictionaryExtensions.GetValueOrDefault Method

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.

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.

Syntax

public static TValue GetValueOrDefault<TKey, TValue>(
    this IReadOnlyDictionary<TKey, TValue> source, 
    TKey key, 
    TValue defaultValue = null
)

Type Parameters

TKey
The type of keys in the dictionary.

TValue
The type of values in the dictionary.

Parameters

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.

Return Value

TValue
defaultValue if the value associated with the specified key is not found; otherwise, the found value.

Exceptions

Exception Description
System.ArgumentNullException source is null.

See Also

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.

Syntax

public static TValue GetValueOrDefault<TValue>(
    this IDictionary<string, object> source, 
    string key, 
    TValue defaultValue = null
)

Type Parameters

TValue
The type of values in the dictionary.

Parameters

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.

Return Value

TValue
defaultValue if the value associated with the specified key is not found; otherwise, the found value.

Exceptions

Exception Description
System.ArgumentNullException source is null.
System.InvalidCastException The specified key is found, but its associated value is not type of TValue.

See Also


This document is generated by DG.