Is there a an easier way to initialize a List>, like a Dictionary?

后端 未结 3 801
遥遥无期
遥遥无期 2021-01-18 08:35

Actually I need something like List> but I want to be able to initialize it like dictionary (i.e. without writing new KeyVa

3条回答
  •  太阳男子
    2021-01-18 08:56

    The code you have typed works fine - further to Mads Togersen's post about the implementation of collection initialisers, the compiler maps the brace-delimited entries ({"key1", "value1"} above) to an Add method on the collection with the same signature - in this case Dictionary.Add(TKey, TValue).

提交回复
热议问题