KGy SOFT

CacheTKey, TValue Constructor (IDictionaryTKey, TValue, IEqualityComparerTKey)

KGy SOFT Core Libraries Help
Initializes a new instance of the CacheTKey, TValue class from the specified dictionary and comparer, with not item loader. The Capacity will be initialized to the number of elements in dictionary.

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

public Cache(
	IDictionary<TKey, TValue> dictionary,
	IEqualityComparer<TKey> comparer = null
)

Parameters

dictionary
Type: System.Collections.GenericIDictionaryTKey, TValue
The dictionary whose elements are added to the CacheTKey, TValue.
comparer (Optional)
Type: System.Collections.GenericIEqualityComparerTKey
The IEqualityComparerT implementation to use when comparing keys. When , EnumComparer<TEnum>.Comparer will be used for enum key types, and EqualityComparer<T>.Default for other types. This parameter is optional.
Default value: .
Remarks

Every key in a CacheTKey, TValue must be unique according to the specified comparer.

This constructor does not specify an item loader and initializes Capacity to the number of elements in the specified dictionary. Meaning, adding new elements manually will drop an element unless you increase Capacity, and reading the indexer with a non-existing key will throw a KeyNotFoundException.

This constructor sets EnsureCapacity to , so no multiple allocations occur during the initialization.

See Also

Reference