KGy SOFT

CircularSortedListTKey, TValueAdd Method

KGy SOFT Core Libraries Help

Namespace:  KGySoft.Collections
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 6.0.0
Syntax

public int Add(
	TKey key,
	TValue value
)

Parameters

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

Return Value

Type: Int32
The zero-based index in the CircularSortedListTKey, TValue at which the key-value pair has been added.
Exceptions

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 CircularSortedListTKey, TValue. for example:

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

If Count already equals Capacity, the capacity of the CircularSortedListTKey, TValue is increased by automatically reallocating the array in internal CircularListT, and the existing elements are copied to the new array before the new element is added.

This method is an O(n) operation for unsorted data, where n is Count. It is an O(1) operation if the new element is added at the end or the head of the list. If insertion causes a resize, the operation is O(n).

See Also

Reference