Is there a more elegant way of adding an item to a Dictionary<> safely?

后端 未结 5 751
梦如初夏
梦如初夏 2020-12-13 16:37

I need to add key/object pairs to a dictionary, but I of course need to first check if the key already exists otherwise I get a \"key already exists in dictionary

5条回答
  •  囚心锁ツ
    2020-12-13 17:32

    What's wrong with...

    dict[key] = view;
    

    It'll automatically add the key if it's non-existent.

提交回复
热议问题