Apr/07
26
Custom Sorting using Compare method(s)
No comments · Posted by nosey in ASP.NET, Reference Sheet
Are you (just like me) one of these people who just can’t remember wether A > B should yield 1 or -1 in a compare method. I know there must be some (higher) form of logic behind it that makes it easily deductible when you just think about it.
Anyway as small reference sheet:
Compare(A,B) or A.CompareTo(B)
This should yield:
| “Compare statement” | Yields | Resulting order |
|---|---|---|
| A > B | 1 | B, A |
| A = B | 0 | non-deterministic |
| A < B | -1 | A, B |
