CollectionExtensions.GetValueOrDefault Metodo

Definizione

Overload

Nome Descrizione
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)

Prova a ottenere il valore associato all'oggetto specificato key in dictionary.

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)

Prova a ottenere il valore associato all'oggetto specificato key in dictionary.

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)

Prova a ottenere il valore associato all'oggetto specificato key in 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);
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

Parametri di tipo

TKey

Tipo delle chiavi nel dizionario.

TValue

Tipo dei valori nel dizionario.

Parametri

dictionary
IReadOnlyDictionary<TKey,TValue>

Dizionario con chiavi di tipo TKey e valori di tipo TValue.

key
TKey

Chiave del valore da ottenere.

Valori restituiti

TValue

Un'istanza TValue. Quando il metodo ha esito positivo, l'oggetto restituito è il valore associato all'oggetto specificato key. Quando il metodo ha esito negativo, restituisce il default valore per TValue.

Eccezioni

dictionary è null.

Si applica a

GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)

Prova a ottenere il valore associato all'oggetto specificato key in 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

Parametri di tipo

TKey

Tipo delle chiavi nel dizionario.

TValue

Tipo dei valori nel dizionario.

Parametri

dictionary
IReadOnlyDictionary<TKey,TValue>

Dizionario con chiavi di tipo TKey e valori di tipo TValue.

key
TKey

Chiave del valore da ottenere.

defaultValue
TValue

Valore predefinito da restituire quando non dictionary è possibile trovare un valore associato all'oggetto specificato key.

Valori restituiti

TValue

Un'istanza TValue. Quando il metodo ha esito positivo, l'oggetto restituito è il valore associato all'oggetto specificato key. Quando il metodo ha esito negativo, restituisce defaultValue.

Eccezioni

dictionary è null.

Si applica a