AllowNullDictionaryTKey, TValueAdd Method

Adds an element with the provided key and value to the AllowNullDictionaryTKey, 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. In this dictionary it can be even .
value  TValue
The value of the element to add.

Implements

IDictionaryTKey, TValueAdd(TKey, TValue)

Remarks

In this dictionary both the key and the value can be .

You can also use the indexer to add new elements by setting the value of a key that does not exist in the AllowNullDictionaryTKey, TValue. for example:

C#
myCollection[myNonexistentKey] = myValue;
However, if the specified key already exists in the AllowNullDictionaryTKey, TValue, setting the indexer overwrites the old value. In contrast, the Add method does not modify existing elements.

This method approaches an O(1) operation unless if insertion causes a resize, in which case the operation is O(n).

Exceptions

ArgumentExceptionAn element with the same key already exists in the AllowNullDictionaryTKey, TValue.

See Also