This code is equivalent to:
static void Main(string[] args) { int[] numbers = { 1, 2, 3, 4, 5 }; Array.Sort(numbers, OnComparison); } private static int OnComparison(int x, int y) { if (x%2 == y%2) return 0; if (x%2 == 1) return 1; return -1; }
I get:
{3, 5, 1, 2, 4}
The sort operation is as follows:
0) {1,2,3,4,5} 1) {1,2,3,4,5} 2) {1,2,3,4,5} 3) {1,2,3,4,5} 4) {1,2,3,4,5} 5) {5,2,3,4,1} 6) {5,2,3,4,1} 7) {5,2,3,4,1} 8) {5,3,2,4,1} 9) {5,3,2,4,1} 10) {5,3,2,4,1} 11) {5,3,2,4,1} 12) {3,5,2,4,1} 13) {3,5,2,4,1} 14) {3,5,1,4,2} 15) {3,5,1,4,2} 16) {3,5,1,4,2} 17) {3,5,1,4,2} 18) {3,5,1,2,4} 19) {3,5,1,2,4} 20) {3,5,1,2,4} 21) {3,5,1,2,4} 22) {3,5,1,2,4} 23) Final: {3,5,1,2,4}
So, in conclusion, it seems why the “why” is due to the fact that the problem is 0, as everyone says, but I'm still not sure.