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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-08-30
猜你喜欢
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2021-10-28
  • 2021-12-30
  • 2022-12-23
相关资源
相似解决方案