Using .Net How to use the sorting method to sort the array in reverse order, i.e. from Z to A?

Using .Net How to use the sort method to sort the array in reverse order, i.e. from Z to A?

+5
source share
3 answers

Specify the appropriate elemental comparator. What version of C # are you using? 3 allows you to do this:

Array.Sort(myarray, (a, b) => b.CompareTo(a));
+11
source

You need to pass an IComparer or Comparison delegate object to the Sort function.

Here is sample code from C # 2.0

   Array.Sort(array,delegate(string a, string b)
    {
        return b.CompareTo(a);
    });

EDIT: skipped an array bit.

+3
source

, , .

, ...

+1

All Articles