Table of Contents

DictionaryExtensions 类

命名空间
ClassIsland.Core.Extensions
程序集
ClassIsland.Core.dll

IDictionary<TKey, TValue>的扩展方法。

public static class DictionaryExtensions
继承
DictionaryExtensions
继承成员

方法

GetOrCreateDefault<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)

尝试获取指定的值。当值不存在时,设置并返回指定的默认值。

public static TValue GetOrCreateDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)

参数

dictionary IDictionary<TKey, TValue>

字典对象

key TKey

要尝试获取的键

defaultValue TValue

如果获取失败,使用的默认值

返回

TValue

如果获取成功,返回获取的值,否则返回默认值。

类型参数

TKey

字典键的类型

TValue

字典值的类型