CollectionExtensions.GetValueOrDefault Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Sobrecargas
| GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) |
Tenta obter o valor associado ao |
| GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) |
Tenta obter o valor associado ao |
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)
- Origem:
- CollectionExtensions.cs
- Origem:
- CollectionExtensions.cs
- Origem:
- CollectionExtensions.cs
Tenta obter o valor associado ao key especificado 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);
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 do tipo TKey e valores do tipo TValue.
- key
- TKey
A chave do valor a ser obtido.
Retornos
Uma instância de TValue. Quando o método é bem-sucedido, o objeto retornado é o valor associado ao key especificado. Quando o método falha, ele retorna o valor default de TValue.
Exceções
dictionary é null.
Aplica-se a
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)
- Origem:
- CollectionExtensions.cs
- Origem:
- CollectionExtensions.cs
- Origem:
- CollectionExtensions.cs
Tenta obter o valor associado ao key especificado 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 do 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 o dictionary não consegue localizar um valor associado ao key especificado.
Retornos
Uma instância de TValue. Quando o método é bem-sucedido, o objeto retornado é o valor associado ao key especificado. Quando o método falha, ele retorna o defaultValue.
Exceções
dictionary é null.