3
Reply

How to initialize Dictionary using collection initialize?

Atulya Panda

Atulya Panda

Nov 26, 2012
5.4k
1

    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.

    Manju lata Yadav
    July 09, 2014
    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");

    keerthi rakasi
    February 28, 2013
    0

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

    Atulya Panda
    November 26, 2012
    0