C# Dictionary增加的方法

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;
        }

posted @ 2015-08-17 12:42  佳序  阅读(5055)  评论(0编辑  收藏  举报