Atulya Panda
How to initialize Dictionary using collection initialize?
Posted by Atulya Panda in ASP.NET Programming on Nov 26, 2012
  • 1
  • 3
  • 4351
Do you know the answer for this question? Post it below.
Posted by Manju lata Yadav on Jul 09, 2014
  • 0

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.

Posted by keerthi rakasi on Feb 28, 2013
  • 0

it will store values in key/value pair.And the syntax is Dictionary obj=new Dictionary(); obj.Add(1,"jan"); obj.Add(2,"feb");

Posted by Atulya Panda on Nov 26, 2012
  • 0

Dictionary t = new Dictionary() { {1, “a”}, {2, “vb”}, {3, “c”}};

C# Corner Hyderabad Developer Conference

Most Popular Companies

Most Popular Job Functions