CollectionExtensions.GetValueOrDefault Metoda
Definice
Přetížení
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) |
Pokusí se získat hodnotu přidruženou k zadanému |
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) |
Pokusí se získat hodnotu přidruženou k zadanému klíči v |
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)
Pokusí se získat hodnotu přidruženou k zadanému key
v dictionary
.Tries to get the value associated with the specified key
in the dictionary
.
public:
generic <typename TKey, typename TValue>
[System::Runtime::CompilerServices::Extension]
static TValue GetValueOrDefault(System::Collections::Generic::IReadOnlyDictionary<TKey, TValue> ^ dictionary, TKey key);
public static TValue? GetValueOrDefault<TKey,TValue> (this System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> dictionary, TKey key);
public static TValue GetValueOrDefault<TKey,TValue> (this System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> dictionary, TKey key);
static member GetValueOrDefault : System.Collections.Generic.IReadOnlyDictionary<'Key, 'Value> * 'Key -> 'Value
<Extension()>
Public Function GetValueOrDefault(Of TKey, TValue) (dictionary As IReadOnlyDictionary(Of TKey, TValue), key As TKey) As TValue
Parametry typu
- TKey
Typ klíčů ve slovníku.The type of the keys in the dictionary.
- TValue
Typ hodnot ve slovníku.The type of the values in the dictionary.
Parametry
- dictionary
- IReadOnlyDictionary<TKey,TValue>
Slovník s klíči typu TKey
a hodnotami typu TValue
.A dictionary with keys of type TKey
and values of type TValue
.
- key
- TKey
Klíč hodnoty, kterou chcete získatThe key of the value to get.
Návraty
- TValue
TValue
Instance.A TValue
instance. Když je metoda úspěšná, vrácený objekt je hodnota přidružená k zadanému objektu key
.When the method is successful, the returned object is the value associated with the specified key
. Pokud se metoda nezdařila, vrátí default
hodnotu pro TValue
.When the method fails, it returns the default
value for TValue
.
Výjimky
dictionary
je null
.dictionary
is null
.
Platí pro
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)
Pokusí se získat hodnotu přidruženou k zadanému klíči v dictionary
.Tries to get the value associated with the specified key in the dictionary
.
public:
generic <typename TKey, typename TValue>
[System::Runtime::CompilerServices::Extension]
static TValue GetValueOrDefault(System::Collections::Generic::IReadOnlyDictionary<TKey, TValue> ^ dictionary, TKey key, TValue defaultValue);
public static TValue GetValueOrDefault<TKey,TValue> (this System.Collections.Generic.IReadOnlyDictionary<TKey,TValue> dictionary, TKey key, TValue defaultValue);
static member GetValueOrDefault : System.Collections.Generic.IReadOnlyDictionary<'Key, 'Value> * 'Key * 'Value -> 'Value
<Extension()>
Public Function GetValueOrDefault(Of TKey, TValue) (dictionary As IReadOnlyDictionary(Of TKey, TValue), key As TKey, defaultValue As TValue) As TValue
Parametry typu
- TKey
Typ klíčů ve slovníku.The type of the keys in the dictionary.
- TValue
Typ hodnot ve slovníku.The type of the values in the dictionary.
Parametry
- dictionary
- IReadOnlyDictionary<TKey,TValue>
Slovník s klíči typu TKey
a hodnotami typu TValue
.A dictionary with keys of type TKey
and values of type TValue
.
- key
- TKey
Klíč hodnoty, kterou chcete získatThe key of the value to get.
- defaultValue
- TValue
Výchozí hodnota, která má být vrácena, pokud dictionary
nelze najít hodnotu přidruženou k zadanému key
.The default value to return when the dictionary
cannot find a value associated with the specified key
.
Návraty
- TValue
TValue
Instance.A TValue
instance. Když je metoda úspěšná, vrácený objekt je hodnota přidružená k zadanému objektu key
.When the method is successful, the returned object is the value associated with the specified key
. V případě, že se metoda nezdařila, vrátí defaultValue
.When the method fails, it returns defaultValue
.
Výjimky
dictionary
je null
.dictionary
is null
.