The weird thing about string comparisons
Another way to show this:
Console.WriteLine("a".CompareTo("b")); // -1
Console.WriteLine("b".CompareTo("a")); // 1
Console.WriteLine('a'.CompareTo('b')); // -1
Console.WriteLine('b'.CompareTo('a')); // 1
Console.WriteLine("~".CompareTo("a")); // -1
Console.WriteLine("a".CompareTo("~")); // 1
Console.WriteLine('~'.CompareTo('a')); // 29
Console.WriteLine('a'.CompareTo('~')); // -29
The difference may be subtle, but it is documented . Comparison in Char.CompareTo(Char)is
based on the encoded values of this instance and value, not their lexicographic characteristics .
At the same time, the documentation forString.CompareTo(String)
performs a word (case sensitive and culture sensitive) comparison using current culture .
.. , (, ).