How to insert values into C# Dictionary on instantiation? -
Does anybody know if there is a way when I can add value to it in the C # dictionary? I can do something but do not want to do this, because dict.Add (int, "string") for each item is something more efficient:
Dictionary; Int, string & gt; () {(0, "string"), (1, "string 2"), (2, "string 3")};
Here's the whole page about doing so:
Example:
In the following code example, a
dictionary < TKey, TValue & gt;
is started with examples ofStudentName
:
var student = new dictionary & lt; Int, studentname & gt; () {{111, new student name {first name = "Sachin", last name = "Karnik", id = 211}}, {112, new student name {first name = "Dina", last name = "Salimzianwa", id = 317 }}, {113, new student name {first name = "andy"}, last name = "ruth", id = 1}}}};
Comments
Post a Comment