CollectionExtensions.GetValueOrDefault 方法

定义

重载

名称 说明
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)

尝试获取与 key 指定的 dictionary值关联的值。

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

尝试获取与 key 指定的 dictionary值关联的值。

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

尝试获取与 key 指定的 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

类型参数

TKey

字典中键的类型。

TValue

字典中值的类型。

参数

dictionary
IReadOnlyDictionary<TKey,TValue>

包含类型 TKey 键和类型的 TValue值的字典。

key
TKey

要获取的值的键。

返回

TValue

实例 TValue 。 方法成功后,返回的对象是与指定 key值关联的值。 方法失败时,它将返回 defaultTValue值。

例外

dictionarynull

适用于

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

尝试获取与 key 指定的 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

类型参数

TKey

字典中键的类型。

TValue

字典中值的类型。

参数

dictionary
IReadOnlyDictionary<TKey,TValue>

包含类型 TKey 键和类型的 TValue值的字典。

key
TKey

要获取的值的键。

defaultValue
TValue

当找不到与指定key值关联的值时dictionary要返回的默认值。

返回

TValue

实例 TValue 。 方法成功后,返回的对象是与指定 key值关联的值。 当方法失败时,它将返回 defaultValue

例外

dictionarynull

适用于