Method TryGetFirstValueByKey
- Namespace
- DisCatSharp.Common
- Assembly
- DisCatSharp.Common.dll
TryGetFirstValueByKey<TKey, TValue>(Dictionary<TKey, TValue?>?, TKey, out TValue?)
Safely tries to extract the value of the first match where target key is found, otherwise null.
public static bool TryGetFirstValueByKey<TKey, TValue>(this Dictionary<TKey, TValue?>? dict, TKey key, out TValue? value) where TKey : notnull
Parameters
dict
Dictionary<TKey, TValue>The dictionary to use.
key
TKeyThe key to search for.
value
TValueThe value to get if succeeded.
Returns
- bool
Whether a value was found through the key.
Type Parameters
TKey
Key type of dictionary.
TValue
Value type of dictionary.