DictionaryExtensionsGetActualValueOrDefaultTKey, TValue, TActualValue(IDictionaryTKey, TValue, TKey, FuncTActualValue) Method

Tries to get the typed value from a dictionary for the given key. In this method defaultValueFactory can return an instance of a different type than TValue.
See the Examples section of the GetValueOrDefaultTActualValue(IDictionaryString, Object, String, TActualValue) method for some examples.


Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.0.0-rc.1
public static TActualValue GetActualValueOrDefault<TKey, TValue, TActualValue>(
	this IDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TActualValue> defaultValueFactory
where TActualValue : TValue


dictionary  IDictionaryTKey, TValue
The dictionary.
key  TKey
The key whose value to get.
defaultValueFactory  FuncTActualValue
A delegate that can be invoked to return a default value if key was not found.

Type Parameters

The type of the stored keys in the dictionary.
Type of the stored values in the dictionary.
The type of the value with the corresponding key to get.

Return Value

The found value or the result of defaultValueFactory 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 IDictionaryTKey, 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).

See Also