CollectionExtensions.GetValueOrDefault 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
| GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey) |
尝试获取与 |
| GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue) |
尝试获取与 |
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey)
- Source:
- CollectionExtensions.cs
- Source:
- CollectionExtensions.cs
- Source:
- CollectionExtensions.cs
尝试获取与 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 实例。 如果方法成功,则返回的对象是与指定的 key 相关联的值。 如果方法失败,则返回 TValue 的 default 值。
例外
dictionary 为 null。
适用于
GetValueOrDefault<TKey,TValue>(IReadOnlyDictionary<TKey,TValue>, TKey, TValue)
- Source:
- CollectionExtensions.cs
- Source:
- CollectionExtensions.cs
- Source:
- CollectionExtensions.cs
尝试获取与 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 实例。 如果方法成功,则返回的对象是与指定的 key 相关联的值。 如果方法失败,则返回 defaultValue。
例外
dictionary 为 null。