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

適用於