1、简单的函数,实现Dictionary如果有就替换,没有就增加的功能。
/// <summary> /// Dictionary增加的方法 /// </summary> /// <typeparam name="TKey"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="dict"></param> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public static Dictionary<TKey, TValue> AddOrReplace<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue value) { dict[key] = value; return dict; }
|
请发表评论