CollectionExtensions.GetValueOrDefault Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Sobrecargas
| Name | Description |
|---|---|
| GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) |
Tenta obter o valor associado ao especificado |
| GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) |
Tenta obter o valor associado ao especificado |
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 Genérico
- 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 de tipo TValue.
- key
- TKey
A chave do valor a obter.
Devoluções
Um TValue exemplo. Quando o método é bem-sucedido, o objeto devolvido é o valor associado ao especificado key. Quando o método falha, devolve 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 Genérico
- 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 de tipo TValue.
- key
- TKey
A chave do valor a obter.
- defaultValue
- TValue
O valor padrão a devolver quando o dictionary não consegue encontrar um valor associado ao especificado key.
Devoluções
Um TValue exemplo. Quando o método é bem-sucedido, o objeto devolvido é o valor associado ao especificado key. Quando o método falha, devolve defaultValue.
Exceções
dictionary é null.