AllowNullDictionaryTKey, TValueItem Property

Gets or sets the value associated with the specified key.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public TValue this[
	TKey key
] { get; set; }

Parameters

key  TKey
The key of the value to get or set. In this dictionary it can be even .

Return Value

TValue
The element with the specified key.

Implements

IDictionaryTKey, TValueItemTKey

Remarks

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

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

C#
myDictionary[myNonexistentKey] = myValue;
However, if the specified key already exists in the AllowNullDictionaryTKey, TValue, setting this property overwrites the old value. In contrast, the Add method throws an ArgumentException, when key already exists in the collection.

Getting or setting this property approaches an O(1) operation.

Exceptions

KeyNotFoundExceptionThe property is retrieved and key is not found.

See Also