ThreadSafeDictionaryTKey, TValueGetOrAdd(TKey, FuncTKey, TValue) Method

Adds a key/value pair to the ThreadSafeDictionaryTKey, TValue by using the specified addValueFactory if the key does not already exist, and returns either the added or the existing value.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public TValue GetOrAdd(
	TKey key,
	Func<TKey, TValue> addValueFactory
)

Parameters

key  TKey
The key of the element to add or whose value should be returned.
addValueFactory  FuncTKey, TValue
The delegate to be used to generate the value, if the key does not already exist.

Return Value

TValue
The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the result of the specified addValueFactory if the key was not in the dictionary.

Exceptions

ArgumentNullExceptionkey or addValueFactory is .

See Also