How to insert values into C# Dictionary on instantiation?

后端 未结 8 1183
刺人心
刺人心 2021-02-01 00:12

Does anyone know if there is a way I can insert values into a C# Dictionary when I create it? I can, but don\'t want to, do dict.Add(int, \"string\") for each item

8条回答
  •  既然无缘
    2021-02-01 00:30

    Dictionary dictionary = new Dictionary { 
       { 0, "string" }, 
       { 1, "string2" }, 
       { 2, "string3" } };
    

提交回复
热议问题