Click or drag to resize

CollectionExtensionsForceValueTKey, TValue(IDictionaryTKey, TValue, TKey, FuncTKey, TValue) Method

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) Version: 2.21.0+44d18b541fc9419ec3c549350a832394661b2a4d
XMLNS for XAML: Not mapped to an xmlns.
Syntax
public static TValue ForceValue<TKey, TValue>(
	this IDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TKey, TValue> generator
)

Parameters

dictionary  IDictionaryTKey, TValue
The dictionary.
key  TKey
The key.
generator  FuncTKey, TValue
The generator function called when a new value needs to be created.

Type Parameters

TKey
The type of the key.
TValue
The type of the value.

Return Value

TValue
The 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