KGy SOFT

CacheTKey, TValueAdd Method

KGy SOFT Core Libraries Help

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

public void 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 types.

Implements

IDictionaryTKey, TValueAdd(TKey, TValue)
Exceptions

ExceptionCondition
ArgumentNullExceptionkey is .
ArgumentExceptionkey already exists in the cache.
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.

See Also

Reference