ThreadSafeDictionaryTKey, TValueAddOrUpdateTArg(TKey, FuncTKey, TArg, TValue, FuncTKey, TValue, TArg, TValue, TArg) Method

Uses the specified delegates to add a key/value pair to the ThreadSafeDictionaryTKey, TValue if the key does not already exist, or to update a key/value pair in the ThreadSafeDictionaryTKey, TValue if the key already exists.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public TValue AddOrUpdate<TArg>(
	TKey key,
	Func<TKey, TArg, TValue> addValueFactory,
	Func<TKey, TValue, TArg, TValue> updateValueFactory,
	TArg factoryArgument
)

Parameters

key  TKey
The key to be added or whose value should be updated.
addValueFactory  FuncTKey, TArg, TValue
A delegate used to generate a value for an absent key.
updateValueFactory  FuncTKey, TValue, TArg, TValue
A delegate used to generate a new value for an existing key based on the key's existing value.
factoryArgument  TArg
An argument to pass into addValueFactory and updateValueFactory.

Type Parameters

TArg
The type of an argument to pass into addValueFactory and updateValueFactory.

Return Value

TValue
The new value for the key. This will be either the result of addValueFactory (if the key was absent) or the result of updateValueFactory (if the key was present).

Exceptions

ArgumentNullExceptionkey, addValueFactory or updateValueFactory is .

See Also