CollectionExtensions.GetValueOrDefault Método

Definición

Sobrecargas

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

Intenta obtener el valor asociado al elemento key especificado en dictionary.

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

Intenta obtener el valor asociado al elemento key especificado en dictionary.

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

Intenta obtener el valor asociado al elemento key especificado en 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

Parámetros de tipo

TKey

Tipo de las claves del diccionario.

TValue

Tipo de los valores del diccionario.

Parámetros

dictionary
IReadOnlyDictionary<TKey,TValue>

Diccionario con claves de tipo TKey y valores de tipo TValue.

key
TKey

Clave del valor que se va a obtener.

Devoluciones

TValue

Instancia de TValue. Cuando el método se ejecuta correctamente, el objeto devuelto es el valor asociado al elemento key especificado. Cuando se produce un error en el método, devuelve el valor default para TValue.

Excepciones

dictionary es null.

Se aplica a

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

Intenta obtener el valor asociado al elemento key especificado en 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

Parámetros de tipo

TKey

Tipo de las claves del diccionario.

TValue

Tipo de los valores del diccionario.

Parámetros

dictionary
IReadOnlyDictionary<TKey,TValue>

Diccionario con claves de tipo TKey y valores de tipo TValue.

key
TKey

Clave del valor que se va a obtener.

defaultValue
TValue

El valor predeterminado que se va a devolver cuando dictionary no pueda encontrar un valor asociado al elemento key especificado.

Devoluciones

TValue

Instancia de TValue. Cuando el método se ejecuta correctamente, el objeto devuelto es el valor asociado al elemento key especificado. Cuando se produce un error en el método, devuelve defaultValue.

Excepciones

dictionary es null.

Se aplica a