StringKeyedDictionaryTValueItem(String) 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[
	string key
] { get; set; }

Parameters

key  String
The key of the value to get or set.

Return Value

TValue
The element with the specified key.

Implements

IDictionaryTKey, TValueItemTKey
IReadOnlyDictionaryTKey, TValueItemTKey

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

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

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

See Also