CollectionExtensions.GetValueOrDefault メソッド

定義

オーバーロード

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

dictionary から、指定した key に関連付けられている値の取得を試みます。

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

dictionary から、指定した key に関連付けられている値の取得を試みます。

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

dictionary から、指定した key に関連付けられている値の取得を試みます。

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

型パラメーター

TKey

ディクショナリ内のキーの型。

TValue

ディクショナリ内の値の型。

パラメーター

dictionary
IReadOnlyDictionary<TKey,TValue>

TKey 型のキーと TValue 型の値を含むディクショナリ。

key
TKey

取得する値のキー。

戻り値

TValue

TValue のインスタンス。 このメソッドが成功した場合、返されるオブジェクトは、指定した key に関連付けられている値になります。 このメソッドが失敗すると、TValuedefault 値が返されます。

例外

dictionarynullです。

適用対象

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

dictionary から、指定した key に関連付けられている値の取得を試みます。

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

型パラメーター

TKey

ディクショナリ内のキーの型。

TValue

ディクショナリ内の値の型。

パラメーター

dictionary
IReadOnlyDictionary<TKey,TValue>

TKey 型のキーと TValue 型の値を含むディクショナリ。

key
TKey

取得する値のキー。

defaultValue
TValue

dictionary が指定した key と関連付けられている値を見つけることができない場合に返す既定値。

戻り値

TValue

TValue のインスタンス。 このメソッドが成功した場合、返されるオブジェクトは、指定した key に関連付けられている値になります。 このメソッドが失敗すると、defaultValue が返されます。

例外

dictionarynullです。

適用対象