interviews.dotnetthread.com

↑ Grab this Headline Animator

Tuesday, September 16, 2008

How to sort an array into descending order?

First sort the array using Array.Sort and then use Array.Reverse

int[] number = new int[] {6, 4, 7};
Array.Sort(number); // sort in ascending order
foreach (int i in number)
{
lblMessage.Text += i + "
";
}
// reverse ie descending order
Array.Reverse(number);
lblMessage.Text += "


";
foreach (int i in number)
{
lblMessage.Text += i + "
";
}

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles