Collection Initializer

codes:

using System;
using System.Collections.Generic;

namespace ObjectInitializeProgs
{
    public class Student
    {
        public int RollNo{ get; set; } 
        public string Name { get; set; }
        public int age { get; set; }
        public string address { get; set; }
    }


    class Program
    {
        static void Main(string[] args)
        {
            List<Student> studentList=new List<Student>() //collection initializers
            {
                new Student(){RollNo = 11,Name="vijay"},
                new Student(){RollNo = 12,Name="Farook"},
                new Student(){RollNo = 14,Name="Araf"}
            };

            foreach (var items in studentList)
            {
                Console.WriteLine(items.RollNo+" "+items.Name);
            }
            Console.Read();
        }
    }
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *