How can I create a new instance of ImmutableDictionary?

前端 未结 5 1806
慢半拍i
慢半拍i 2020-12-15 15:18

I would like to write something like this:

var d = new ImmutableDictionary { { \"a\", 1 }, { \"b\", 2 } };

(using

5条回答
  •  庸人自扰
    2020-12-15 15:24

    Or this

    ImmutableDictionary.Empty
       .Add("a", 1)
       .Add("b", 2);
    

    There is also AddRange method available.

提交回复
热议问题