CacheTKey, TValue(IDictionaryTKey, TValue, IEqualityComparerTKey) Constructor

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

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public Cache(
	IDictionary<TKey, TValue> dictionary,
	IEqualityComparer<TKey>? comparer = null
)

Parameters

dictionary  IDictionaryTKey, TValue
The dictionary whose elements are added to the CacheTKey, TValue.
comparer  IEqualityComparerTKey  (Optional)
The IEqualityComparerT implementation to use when comparing keys. If , EnumComparer<TEnum>.Comparer will be used for enum key types when targeting the .NET Framework, and EqualityComparer<T>.Default in other cases. 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