Επεξεργασία

Κοινή χρήση μέσω


CollectionExtensions.GetValueOrDefault Method

Definition

Overloads

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

Tries to get the value associated with the specified key in the dictionary.

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

Tries to get the value associated with the specified key in the dictionary.

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

Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs

Tries to get the value associated with the specified key in the 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

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Parameters

dictionary
IReadOnlyDictionary<TKey,TValue>

A dictionary with keys of type TKey and values of type TValue.

key
TKey

The key of the value to get.

Returns

TValue

A TValue instance. When the method is successful, the returned object is the value associated with the specified key. When the method fails, it returns the default value for TValue.

Exceptions

dictionary is null.

Applies to

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

Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs
Source:
CollectionExtensions.cs

Tries to get the value associated with the specified key in the 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

Type Parameters

TKey

The type of the keys in the dictionary.

TValue

The type of the values in the dictionary.

Parameters

dictionary
IReadOnlyDictionary<TKey,TValue>

A dictionary with keys of type TKey and values of type TValue.

key
TKey

The key of the value to get.

defaultValue
TValue

The default value to return when the dictionary cannot find a value associated with the specified key.

Returns

TValue

A TValue instance. When the method is successful, the returned object is the value associated with the specified key. When the method fails, it returns defaultValue.

Exceptions

dictionary is null.

Applies to