Windows Phone Developers

Sunday, April 11, 2010

How to Add and Sort Items in a list using C#

Adding and Sorting List Items using .NET (C#)

The following example creates a Generic list of IPL teams and sorts them


The following code does it:

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


            Console.WriteLine("List Before Sorting");
            Console.WriteLine("=======================");
            foreach (string IPL in lstIPLTeams)
            {
                Console.WriteLine(IPL.ToString());
            }

            //Sort the Items
            lstIPLTeams.Sort();

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

Here is the output



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

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005