5
Reply

How can we sort the elements of the array in descending order?

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

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

    Array.Reverse(list);

    Using Linq

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

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

    // 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)));

    First Sort the array in ascending order then reserve it.

    //sort
    Array.Sort(list);
    // Descending order
    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.