Click or drag to resize
DictionaryExtensionMethodsGetValueOrDefaultTKey, TValue Method (IDictionaryTKey, TValue, TKey, FuncTValue)
Tries to get the value with the specified key from the dictionary, and uses the passed default value provider to return a value if the key could not be found.

Namespace: Slash.Collections.Extensions
Assembly: Slash.Collections (in Slash.Collections.dll) Version: 1.0.6018.40177
Syntax
public static TValue GetValueOrDefault<TKey, TValue>(
	this IDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TValue> defaultValueProvider
)

Parameters

dictionary
Type: System.Collections.GenericIDictionaryTKey, TValue
Dictionary to get the value from.
key
Type: TKey
Key of the value to get.
defaultValueProvider
Type: SystemFuncTValue
Default value provider to use to return a value if the key could not be found.

Type Parameters

TKey
Type of the dictionary keys.
TValue
Type of the dictionary values.

Return Value

Type: TValue
Value with the specified key, if found, and a value provided by defaultValueProvider otherwise.

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