Gajendra Jangid
How can we sort the elements of the array in descending order?
By Gajendra Jangid in Software Testing on Mar 13 2018
  • Pavan Ramamurthy
    Mar, 2021 30

    int[] list = {88, 13, 93, 25, 77};

    Inorder to Sort in descending order, we can use the below code.

    Array.Reverse(list);

    • 1
  • Amit Kumar Santra
    May, 2021 4

    Using Linq

    // Sort the arr in decreasing order and return a array

    1. arr = arr.OrderByDescending(c => c).ToArray();

    • 0
  • Amit Kumar Santra
    May, 2021 4

    // Sort the arr from last to first.
    // compare every element to each other

    1. Array.Sort<int>(arr, new Comparison<int>(
    2. (i1, i2) => i2.CompareTo(i1)));

    • 0
  • Amit Kumar Santra
    May, 2021 4

    First Sort the array in ascending order then reserve it.

    //sort
    Array.Sort(list);
    // Descending order
    Array.Reverse(list);

    • 0
  • Shweta Lodha
    Feb, 2021 1

    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.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS