Can't add keyValuePair directly to Dictionary

后端 未结 8 1139
半阙折子戏
半阙折子戏 2020-12-18 18:45

I wanted to add a KeyValuePair to a Dictionary and I couldn\'t. I have to pass the key and the value separately, which must

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 19:13

    What would be wrong with just adding it into your project as an extension?

    namespace System.Collection.Generic
    {
        public static class DictionaryExtensions
        {
            public static void AddKeyValuePair(this IDictionary me, KeyValuePair other)
            {
                me.Add(other.Key, other.Value);
            }
        }
    }
    

提交回复
热议问题