 | 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.ExtensionsAssembly: Slash.Collections (in Slash.Collections.dll) Version: 1.0.6018.40177
Syntaxpublic static TValue GetValueOrDefault<TKey, TValue>(
this IDictionary<TKey, TValue> dictionary,
TKey key,
Func<TValue> defaultValueProvider
)
<ExtensionAttribute>
Public Shared Function GetValueOrDefault(Of TKey, TValue) (
dictionary As IDictionary(Of TKey, TValue),
key As TKey,
defaultValueProvider As Func(Of TValue)
) As TValue
public:
[ExtensionAttribute]
generic<typename TKey, typename TValue>
static TValue GetValueOrDefault(
IDictionary<TKey, TValue>^ dictionary,
TKey key,
Func<TValue>^ defaultValueProvider
)
[<ExtensionAttribute>]
static member GetValueOrDefault :
dictionary : IDictionary<'TKey, 'TValue> *
key : 'TKey *
defaultValueProvider : Func<'TValue> -> 'TValue
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