StringKeyedDictionaryTValueAdd Method

Adds an element with the provided key and value to the StringKeyedDictionaryTValue.

Definition

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

Parameters

key  String
The key of the element to add.
value  TValue
The value of the element to add. The value can be for reference and NullableT types.

Implements

IDictionaryTKey, TValueAdd(TKey, TValue)

Remarks

A key cannot be , but a value can be, if the type of values in the sorted list, TValue, is a reference or NullableT type.

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

C#
myCollection["myNonexistentKey"] = myValue;
However, if the specified key already exists in the StringKeyedDictionaryTValue, 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

ArgumentNullExceptionkey is .
ArgumentExceptionAn element with the same key already exists in the StringKeyedDictionaryTValue.

See Also