KGy SOFT

CircularSortedListTKey, TValueItem Property

KGy SOFT Core Libraries Help
Gets or sets the value associated with the specified key.

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

public TValue this[
	TKey key
] { get; set; }

Parameters

key
Type: TKey
The key of the value to get or set.

Return Value

Type: TValue
The element with the specified key.

Implements

IDictionaryTKey, TValueItemTKey
IReadOnlyDictionaryTKey, TValueItemTKey
Exceptions

ExceptionCondition
ArgumentNullExceptionkey is .
KeyNotFoundExceptionThe property is retrieved and key is not found.
Remarks

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

If the key is not found when a value is being retrieved, KeyNotFoundException is thrown. If the key is not found when a value is being set, the key and value are added.

You can also use this property 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 this property overwrites the old value. In contrast, the Add method throws an ArgumentException, when key already exists in the collection.

Retrieving the value of this property is an O(log n) operation, where n is Count. Setting the property is an O(1) operation if the key is at the first or last position. Otherwise, setting this property is an O(log n) operation, if the key already exists in the CircularSortedListTKey, TValue. If the key is not in the list, and the new element is not at the first or last position, setting the property is an O(n) operation. If insertion causes a resize, the operation is O(n).

See Also

Reference