DictionaryExtensionsGetValueOrDefaultTKey, TValue(IEnumerableKeyValuePairTKey, TValue, TKey, TValue) Method

Tries to get a value from the provided dictionary for the given key.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static TValue GetValueOrDefault<TKey, TValue>(
	this IEnumerable<KeyValuePair<TKey, TValue>> dictionary,
	TKey key,
	TValue defaultValue
)

Parameters

dictionary  IEnumerableKeyValuePairTKey, TValue
The dictionary.
key  TKey
The key whose value to get.
defaultValue  TValue
The default value to return if key was not found.

Type Parameters

TKey
The type of the stored keys in the dictionary.
TValue
Type of the stored values in the dictionary.

Return Value

TValue
The found value or defaultValue if key was not found in the dictionary.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableKeyValuePairTKey, TValue. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

See Also