I have a question related to string comparison vs. character comparison.
Characters >
and 0
(zero) have following decimal values 62
When you compare the characters '>'
and '0'
, you are comparing their ordinal values.
To get the same behaviour from a string comparison, supply the ordinal string comparison type:
Console.WriteLine(string.Compare(">", "0", StringComparison.Ordinal));
Console.WriteLine(string.Compare(">", "0", StringComparison.InvariantCulture));
Console.WriteLine(string.Compare(">", "0", StringComparison.CurrentCulture));
The current culture is used by default, which has a sorting order intended to sort strings 'alphabetically' rather in strictly lexical order, for some definition of alphabetically.