 | DictionaryExtensionMethodsGetValueOrDefaultTKey, TValue Method (IDictionaryTKey, TValue, TKey, TValue) |
Tries to get the value with the specified key from the
dictionary, and returns the passed default 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,
TValue defaultValue
)
<ExtensionAttribute>
Public Shared Function GetValueOrDefault(Of TKey, TValue) (
dictionary As IDictionary(Of TKey, TValue),
key As TKey,
defaultValue As TValue
) As TValue
public:
[ExtensionAttribute]
generic<typename TKey, typename TValue>
static TValue GetValueOrDefault(
IDictionary<TKey, TValue>^ dictionary,
TKey key,
TValue defaultValue
)
[<ExtensionAttribute>]
static member GetValueOrDefault :
dictionary : IDictionary<'TKey, 'TValue> *
key : 'TKey *
defaultValue : 'TValue -> 'TValue
Parameters
- dictionary
- Type: System.Collections.GenericIDictionaryTKey, TValue
Dictionary to get the value from.
- key
- Type: TKey
Key of the value to get.
- defaultValue
- Type: TValue
Default value to return if the specified 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
defaultValue 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