How can you sort the elements of the array in descending order

A) Sort methods
B) Reverse methods
C) By calling Sort and then Reverse methods
D) Can’t sort in descending

Editorial / Best Answer

Answered by: Prakhar

  • Apr 12th, 2006


        int[] arr = new int[3];
        arr[0] = 4;
        arr[1] = 1;
        arr[2] = 5;

        Array.Sort(arr);
        Array.Reverse(arr);

Showing Answers 1 - 11 of 11 Answers

Prakhar

  • Apr 12th, 2006
 

        int[] arr = new int[3];
        arr[0] = 4;
        arr[1] = 1;
        arr[2] = 5;

        Array.Sort(arr);
        Array.Reverse(arr);

rfb99

  • Dec 16th, 2011
 

It is far more elegant and efficient to do something like

Array.Sort(arr, delegate(int x, int y) { return y.CompareTo(x); });

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions