Windows Phone Developers

Sunday, April 11, 2010

How to Add an Array to List using C# /.NET

Add Range to List using C# / .NET

Let us take our own IPL example. The current IPL has eight teams that are part of the list

            List lstIPLTeams = new List();

            lstIPLTeams.Add("Mumbai Indians");
            lstIPLTeams.Add("Chennai SuperKings");
            lstIPLTeams.Add("Kolkatta KnightRiders");
            lstIPLTeams.Add("Deccan Chargers");
            lstIPLTeams.Add("Rajastan Royals");
            lstIPLTeams.Add("Delhi DareDevils");
            lstIPLTeams.Add("KingsXI Punjab");
            lstIPLTeams.Add("RC Bangalore");




From next year two new teams- Pune and Kochi - will be part of IPL

Hence we are adding those two teams to an Array and adding the array using AddRange method

            string[] NewIPLTeams = { "Pune", "Kochi" };
            lstIPLTeams.AddRange(NewIPLTeams);

            Console.WriteLine("\nList After Add Range");
            Console.WriteLine("=======================");
            foreach (string IPL in lstIPLTeams)
            {
                Console.WriteLine(IPL.ToString());
            }


This will add Pune and Kochi to end of the list Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment