I have an array of objects containing the following data.

``unsortedArray =A : 1B : 2C : 3D : 4E : 5F : 6G : 7H : 8I : 9J : 10K : 11L : 12M : 13N : 14O : 15P : 16Q : 17R : 18S : 19T : 20U : 21V : 22W : 23X : 24Y : 25Z : 26``

I'm trying to sort these objects so that the objects with the higher integer values appear further up in the list, but am receiving the following output with the sort..

``sortedArray =Z : 26X : 24W : 23V : 22U : 21T : 20S : 19R : 18Q : 17P : 16O : 15N : 14M : 13L : 12K : 11J : 10I : 9H : 8G : 7F : 6E : 5D : 4C : 3B : 2Y : 25A : 1``

Below is the code I am using..

``var sortedArray= unsortedArray;Array.Sort(sortedArray, (x, y) => y.Point >= x.Point ? y.Point : x.Point);``

Note: In the code, `Point` refers to the integer value in the object.

What am I doing incorrectly?

The second argument you pass to `Array.Sort` is an `IComparer<T>`. From the documentation:

Return Value Type: System.Int32 A signed integer that indicates the relative values of x and y, as shown in the following table.

If you return a value according to the above table and use `Sort`, the array will be sorted in ascending order, which is the opposite of what you want. This means that you should return a negative value if x is larger than y, and a positive value if x is less than y!

``````Array.Sort(sortedArray, (x, y) => y.Point - x.Point);
``````

replace

``````Array.Sort(sortedArray, (x, y) => y.Point >= x.Point ? y.Point : x.Point);
``````

with

``````Array.Sort(sortedArray, (x, y) => y.Point >= x.Point ? 1 : -1);
``````

Top