| CollectionExtensionsForceValueTKey, TValue Method (IDictionaryTKey, TValue, TKey, TValue) |
Gets the value associated with the specified key from the dictionary, or creates a new entry if the dictionary does not contain a value associated with the key.
Namespace:
TomsToolbox.Essentials
Assembly:
TomsToolbox.Essentials (in TomsToolbox.Essentials.dll)
Syntax public static TValue ForceValue<TKey, TValue>(
this IDictionary<TKey, TValue> dictionary,
TKey key,
TValue defaultValue
)
<ExtensionAttribute>
Public Shared Function ForceValue(Of TKey, TValue) (
dictionary As IDictionary(Of TKey, TValue),
key As TKey,
defaultValue As TValue
) As TValue
Parameters
- dictionary
- Type: System.Collections.GenericIDictionaryTKey, TValue
The dictionary. - key
- Type: TKey
The key. - defaultValue
- Type: TValue
The value that will be added to the dictionary if the dictionary does not contain a value associated with the key.
Type Parameters
- TKey
- The type of the key.
- TValue
- The type of the value.
Return Value
Type:
TValueThe element with the specified key.
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