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"} };