Can't add keyValuePair directly to Dictionary

后端 未结 8 1118
半阙折子戏
半阙折子戏 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-18 19:00

    Should somebody really want to do this, here is an Extension

        public static void Add(this IDictionary dic, KeyValuePair KVP)
        {
            dic.Add(KVP.Key, KVP.Value);
        }
    

    but i would recommend to not do this if there is no real need to do this

提交回复
热议问题