Using Linq
// Sort the arr in decreasing order and return a array
arr = arr.OrderByDescending(c => c).ToArray();
Interviews5 answers
Using Linq
// Sort the arr in decreasing order and return a array
arr = arr.OrderByDescending(c => c).ToArray();
// Sort the arr from last to first.
// compare every element to each other
Array.Sort<int>(arr, new Comparison<int>((i1, i2) => i2.CompareTo(i1)));
First Sort the array in ascending order then reserve it.
//sort
Array.Sort(list);
// Descending order
Array.Reverse(list);
int[] list = {88, 13, 93, 25, 77};
Inorder to Sort in descending order, we can use the below code.
Array.Reverse(list);
It’s just reverse of sorting by ascending. In asc order we compare with min values, whereas in case of desc order we go with max values.
Answer an interview question and earn +10 SHARP for every answer.
See unanswered questions