DictionaryExtensionsGetValueOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey) Method

Tries to get a value from a 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>(
	IDictionary<TKey, TValue> dictionary,
	TKey key
)

Parameters

dictionary  IDictionaryTKey, TValue
The dictionary.
key  TKey
The key whose value to get.

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 the default value of TValue if key was not found in the dictionary.

Remarks

This method can be used as an extension method when targeting .NET Framework/.NET Standard 2.0 but is a regular method when targeting .NET Core 2.0/.NET Standard 2.1 or later to avoid collision with the similar extension method in .NET Core 2.0 and above.

See Also