Table of Contents

GetValueOrDefault Method

Definition

Namespace
Cuemon.Extensions.Collections.Generic
Assemblies
Cuemon.Extensions.Collections.Generic.dll
Source
src/Cuemon.Extensions.Collections.Generic/DictionaryExtensions.cs

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

dictionary IDictionary<TKey, TValue>

The IDictionary<TKey, TValue> to extend.

key TKey

The key of the value to get.

defaultProvider Func<TValue>

The function delegate that will provide a default value when the key does not exists in the dictionary.

Returns

TValue

Either the value associated with the specified key or a default value through defaultProvider when the key does not exists.

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Exceptions

ArgumentNullException

dictionary cannot be null -or- key cannot be null -or- defaultProvider cannot be null.