CacheTKey, TValueAdd Method

Adds an element with the provided key and value to the CacheTKey, TValue.

Definition

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

Parameters

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

Implements

IDictionaryTKey, TValueAdd(TKey, TValue)

Remarks

You need to call this method only when this CacheTKey, TValue instance was initialized without using an item loader. Otherwise, you need only to read the get accessor of the indexer property, which automatically invokes the item loader to add new items.

If the key of element already exists in the cache, this method throws an exception. In contrast, using the setter of the indexer property replaces the old value with the new one.

If you want to renew an element in the evaluation order, use the Touch method.

If EnsureCapacity is this method approaches an O(1) operation. Otherwise, when the capacity of the inner storage must be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

Exceptions

ArgumentNullExceptionkey is .
ArgumentExceptionkey already exists in the cache.

See Also