What is Object and Collection initialization in C#? Example.

class Program
    {
        static void Main(string[] args)
        {
            List<Employee> emp = new List<Employee> {
                new Employee{Name="Kulshresth0",Address="Noida0"},
                new Employee{Name="Kulshresth1",Address="Noida1"},
                new Employee{Name="Kulshresth2",Address="Noida2"},
                new Employee{Name="Kulshresth3",Address="Noida3"},
            };
            foreach(Employee em in emp)
            {
                Console.WriteLine("Name : "+em.Name +" "+"Address : "+em.Address);
            }
            Console.ReadLine();
        }
    }-----------------------------

class  Employee
    {
        public string Name { get; set; }
        public string Address { get; set; }
    }
Share:

No comments:

Post a Comment

Saturday, 29 June 2019

What is Object and Collection initialization in C#? Example.

class Program
    {
        static void Main(string[] args)
        {
            List<Employee> emp = new List<Employee> {
                new Employee{Name="Kulshresth0",Address="Noida0"},
                new Employee{Name="Kulshresth1",Address="Noida1"},
                new Employee{Name="Kulshresth2",Address="Noida2"},
                new Employee{Name="Kulshresth3",Address="Noida3"},
            };
            foreach(Employee em in emp)
            {
                Console.WriteLine("Name : "+em.Name +" "+"Address : "+em.Address);
            }
            Console.ReadLine();
        }
    }-----------------------------

class  Employee
    {
        public string Name { get; set; }
        public string Address { get; set; }
    }

No comments:

Post a Comment

Popular

Total Pageviews

Archive