When I compare strings containing positive/negative numbers, for example:
int res1 = "-1".CompareTo("1");
int res2 = "-1".CompareTo("2");
res1 equals 1.
res2 equals -1.
How does String.CompareTo work?? That would mean it is order is "2 -1 1"...
When I compare strings containing positive/negative numbers, for example:
int res1 = "-1".CompareTo("1");
int res2 = "-1".CompareTo("2");
res1 equals 1.
res2 equals -1.
How does String.CompareTo work?? That would mean it is order is "2 -1 1"...
From MSDN:
Certain nonalphanumeric characters might have special weights assigned to them. For example, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list.
Edit: Forgot to mention, this is related to the CompareOptions enumeration used by string.Compare.