正文
DictionaryHelper
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
/// <summary>
/// DictionaryHelper
/// </summary>
public static class DictionaryHelper
{
/// <summary>
/// Put 扩展字典方法 存在时更改,不存在时添加
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="dictionary"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static Dictionary<TKey, TValue> Put<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
if (dictionary.ContainsKey(key))
{
dictionary[key] = value;
}
else
{
dictionary.Add(key, value);
} return dictionary;
} /// <summary>
/// Put 扩展字典方法 存在时更改,不存在时添加
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
/// <param name="dictionary"></param>
/// <param name="keyValuePair"></param>
/// <returns></returns>
public static Dictionary<TKey, TValue> Put<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, KeyValuePair<TKey, TValue> keyValuePair)
{
return dictionary.Put(keyValuePair.Key, keyValuePair.Value);
}
}