当我比较包含正数/负数的字符串时,例如:
int res1 = "-1".CompareTo("1");
int res2 = "-1".CompareTo("2");
res1 equals 1.
res2 equals -1.
String.CompareTo 是如何工作的?这意味着它的顺序是“2 -1 1”...
最佳答案
来自 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.
编辑:忘了说了,这跟string.Compare
使用的CompareOptions
枚举有关。
关于c# - String.CompareTo 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1358659/