Home  »  Articles  »  C#.Net  »

Sort string Array in C#.Net

 Posted By : Manoranjan SahooPosted Date : 18/08/2011 10:47:05 AM Category : C#.Net Points : 5

Sometimes we need to sort our string array using the ASP.Net and C# programming language. The C# language and .NET Framework has several collection sorting methods. In this article i am going to explain about Array Sorting.

Example :

Here we have string[] strListArray in our C# program. This array contains some country name. We need to sort these country name in array. We are going to sort in Ascending order means country name starts with A comes first and then the name starts with B and so on.

To demonstration this we need to create one string array first.
Code :


string[] strListArray = new string[]
{
    "India",
    "Japan",
    "Italy",
    "Europe",
    "America",
    "Vietnam",
    "Newziland",
    "China",
    "UAE",
    "Nepal",
    "Srilanka",
    "Thailand",
    "Bangladesh",
    "Australia",
    "Zimbabwe",
    "South Africa",
    "Canada",
    "Iran",
    "Indonesia"
};


Now we want to sort the above array using Array.sort method. Check below code :

Code :


Array.Sort(strListArray);
foreach (string c in strListArray)
{
    Response.Write(c);
}

Responses
 Author : prakash pradeep Member Level : BronzeDate : 13/04/2012 08:40:37 PM Points : 2

Hi All,

Sorting array article with all possible things .I have written the article please visit the following Blog :

http://moretoc.blogspot.in/2012/04/sorting-arrays-in-c.html



Post Reply
Login to post Response.