How to sort an array into descending order?

 Posted by Raja on 9/8/2008 | Category: C# Interview questions | Views: 9232
Answer:

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

Eg.


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


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response