CollectionExtensions.GetValueOrDefault Método

Definição

Sobrecargas

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

Tenta obter o valor associado ao especificado key no dictionary.

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

Tenta obter o valor associado ao especificado key no dictionary.

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

Tenta obter o valor associado ao especificado key no 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

Parâmetros de tipo

TKey

O tipo das chaves no dicionário.

TValue

O tipo dos valores no dicionário.

Parâmetros

dictionary
IReadOnlyDictionary<TKey,TValue>

Um dicionário com chaves de tipo TKey e valores do tipo TValue.

key
TKey

A chave do valor a ser obtido.

Retornos

TValue

Uma instância de TValue. Quando o método é bem-sucedido, o objeto retornado é o valor associado ao especificado key. Quando o método falha, ele retorna o default valor para TValue.

Exceções

dictionary é null.

Aplica-se a

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

Tenta obter o valor associado ao especificado key no 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

O tipo das chaves no dicionário.

TValue

O tipo dos valores no dicionário.

Parâmetros

dictionary
IReadOnlyDictionary<TKey,TValue>

Um dicionário com chaves de tipo TKey e valores do tipo TValue.

key
TKey

A chave do valor a ser obtido.

defaultValue
TValue

O valor padrão a ser retornado quando não dictionary é possível encontrar um valor associado ao especificado key.

Retornos

TValue

Uma instância de TValue. Quando o método é bem-sucedido, o objeto retornado é o valor associado ao especificado key. Quando o método falha, ele retorna defaultValue.

Exceções

dictionary é null.

Aplica-se a