ThreadSafeDictionaryTKey, TValueAdd Method

Adds an element with the provided key and value to the ThreadSafeDictionaryTKey, TValue.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public void Add(
	TKey key,
	TValue value
)

Parameters

key  TKey
The key of the element to add.
value  TValue
The value of the element to add. The value can be for reference types.

Implements

IDictionaryTKey, TValueAdd(TKey, TValue)

Remarks

If the key of element already exists in the dictionary, this method throws an exception. In contrast, using the setter of the indexer property replaces the old value with the new one.

If multiple values are added to this ThreadSafeDictionaryTKey, TValue concurrently, then you should use the TryAdd method instead, which simply returns if the key to add already exists in the dictionary.

Exceptions

ArgumentNullExceptionkey is .
ArgumentExceptionkey already exists in the dictionary.

See Also