How to initialize list with declaration in C#

08 May 2014, 05:30 AM

You can easily assign the values to the List during declaration in C#. see the example below.

 
 var list = new List<Student>()
                               {
                                  new Student() {Id = 1, Name = "item 1"},
                                  new Student() {Id = 2, Name = "item 2"},
                                  new Student() {Id = 3, Name = "item 3"}
                               };

Related Contents

15 May 2014, 08:07 AM
C#, LINQ, List
15 May 2014, 07:54 AM
C#, LINQ, List
29 Apr 2014, 03:07 AM
C#, Generic
29 Apr 2014, 02:51 AM
C#, Generic
About
Explains how to assign values to List with declaration

Date Posted 08 May 2014, 05:23 AM
Author Brainy Solutions
Views 987
;