Create List in C#

class Program

{

    static void Main(string[] args)

    {

        List_example List_obj = new List_example();

        List<List_example> mylist = new List<List_example>();

        mylist.Add(new List_example { Empname = "Ajay", Cityname = "Bangalore", Mob_number = 9091236790 });

        mylist.Add(new List_example { Empname = "Nisha", Cityname = "Hyd", Mob_number = 9191236790 });

        mylist.Add(new List_example { Empname = "John", Cityname = "Jaipur", Mob_number = 9291236790 });

        mylist.Add(new List_example { Empname = "Sam", Cityname = "Delhi", Mob_number = 9891236790 });

        for (int l = 0; l <= mylist.Count - 1; l++)

        {

            Console.WriteLine("EmpName=" + mylist[l].Empname + " , " + "CityName=" + mylist[l].Cityname + " , " + "MobileNumber=" + mylist[l].Mob_number);

        }

        Console.ReadLine();

    }

}

class List_example

{

    string empname;

    string cityname;

    long mob_number;

    public long Mob_number

    {

        get { return mob_number; }

        set { mob_number = value; }

    }

    public string Empname

    {

        get { return empname; }

        set { empname = value; }

    }

    public string Cityname

    {

        get { return cityname; }

        set { cityname = value; }

    }

}

 

 

 

 

Ebook Download
View all
Learn
View all