How to initialize Dictionary using collection initialize?
Atulya Panda
Dictionary students = new Dictionary() {{ 111, new StudentName {FirstName="Sachin", LastName="Karnik", ID=211}},{ 112, new StudentName {FirstName="Dina", LastName="Salimzianova", ID=317}},{ 113, new StudentName {FirstName="Andy", LastName="Ruth", ID=198}} };The innermost braces enclose the object initializer for the StudentName, and the outermost braces enclose the initializer for the key/value pair that will be added to the students Dictionary. Finally, the whole collection initializer for the dictionary is enclosed in braces.
it will store values in key/value pair.And the syntax is Dictionary obj=new Dictionary(); obj.Add(1,"jan"); obj.Add(2,"feb");
Dictionary t = new Dictionary() { {1, “a”}, {2, “vb”}, {3, “c”}};