How does String.CompareTo work?
When I compare strings containing positive / negative numbers like:
int res1 = "-1".CompareTo("1");
int res2 = "-1".CompareTo("2");
res1 is
1.res2 is -1.
How does String.CompareTo work? This would mean that the order is "2 -1 1" ...
+2
Kevin Doyon
source
to share
1 answer
From MSDN :
Certain non-alpha-numeric characters may have special weights, theirs. For example, a hyphen ("-") may have very little weight assigned to it so that "coop" and "coop" appear next to each other in a sorted list.
Edit: Forgot to mention, this has to do with the enum CompareOptions
used string.Compare
.
+8
Bryan menard
source
to share