KGy SOFT

CacheTKey, TValueTryGetValue Method

KGy SOFT Core Libraries Help
Tries to gets the value associated with the specified key without using the item loader passed to the constructor.

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

public bool TryGetValue(
	TKey key,
	out TValue value
)

Parameters

key
Type: TKey
The key whose value to get.
value
Type: 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

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

Implements

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

ExceptionCondition
ArgumentNullExceptionkey is .
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.

See Also

Reference