Recently I've learned a (ehm...) thing. funny . Or, equally, that . It isn't true that the inverse of a negative number is a positive number (x < 0) => (-x > 0) You could say «Hey, -(-5) == 5». Yes, that's true. We can test it this way: [ ] { x = ; y = -x; Assert.IsTrue(y > ); } Test ( ) public void TestInverse int -5 int 0 But what if we consider ? edge cases [Test] public TestInverse_EdgeCase() { int x = int.MinValue; int y = -x; Assert.IsTrue(y > ); } void 0 It will fail. Miserably. The reason The reason is simple: . In fact, the range of int is to . The inverse of would cause overflow and returns the same value. the sign occupies space -2,147,483,648 2,147,483,647 -2,147,483,648 The lesson Why am I pointing at this? Imagine you are implementing a CompareTo(x, y) method, you know, the usual one that returns if the values are considered equal, if x < y, and if x > y. 0 -1 1 You could use this method to sort an array. Now you want to sort that array descending. What to do? This edge case explains why it is a terrible idea to use CompareTo(-x, -y). Results can be unexpected. The best solution is to simply switch the parameters: CompareTo(y, x). Conclusion This example teaches us that we must know the basics of a language not only in terms of syntax but also in terms of inner handling. If we just used without knowing how it is made, we would fall into this mistake without knowing why. int Previously published at https://www.code4it.dev/blog/csharp-sorting-mistake