CacheTKey, TValueTryGetValue Method

Tries to gets the value associated with the specified key without using the item loader passed to the constructor.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public bool TryGetValue(
	TKey key,
	out TValue value
)

Parameters

key  TKey
The key whose value to get.
value  TValue
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Return Value

Boolean
, if cache contains an element with the specified key; otherwise, .

Implements

IDictionaryTKey, TValueTryGetValue(TKey, TValue)
IReadOnlyDictionaryTKey, TValueTryGetValue(TKey, TValue)

Remarks

Use this method if the CacheTKey, TValue was initialized without an item loader, or when you want to determine if a key exists in the CacheTKey, TValue and if so, you want to get the value as well. Reading the indexer property would transparently load a non-existing element by calling the item loader delegate that was passed to the constructor.

Works exactly the same way as in case of DictionaryTKey, TValue class. If key is not found, does not use the item loader passed to the constructor.

If the key is not found, then the value parameter gets the appropriate default value for the type TValue; for example, 0 (zero) for integer types, for Boolean types, and for reference types.

This method approaches an O(1) operation.

Exceptions

See Also