c# - Can I use a collection initializer for Dictionary<TKey, TValue> entries? -


I want to use the archive starters for the next bit code:

  public dictionary & Lt; Int, string & gt; GetNames () {Dictionary & lt; Int, string & gt; Name = New Dictionary & lt; Int, string & gt; (); Name. Add (1, "Adam"); Name. Add (2, "Bart"); Name. Add (3, "Charlie"); Name back; }  

So generally there should be something like this:

  new dictionary & lt; Int, string & gt; {1, "Adam", 2, "Bart" ...  

But what is the correct syntax for this?

  var name = new dictionary & lt; Int, string & gt; {{1, "Adam"}, {2, "Bart"}, {3, "Charlie"}};  

Comments