的String.Compare行为行为、String、Compare

2023-09-05 23:40:17 作者:一个人不够不够不够°

这怎么可能呢? (这是从在VS2008即时窗口)

 的String.Compare?( - ,+)
-1
?的String.Compare( -  0,0)
1
 

解决方案

从上的的String.Compare (重点煤矿):

  

比较使用当前的文化,以获得区域性特定信息,如大小写规则和单个字符的字母顺序。例如,一种文化可以指定字符的某些组合被视为单个字符,或大小写字符以特定方式进行比较,或一个字符的排序顺序取决于$ P $字符pcede或按照它

How this can be ? (This is taken from the immediate window in VS2008)

?string.Compare("-", "+")
-1
?string.Compare("-0", "+0")
1
String类的compareTo String str

解决方案

From the remarks on String.Compare (emphasis mine):

The comparison uses the current culture to obtain culture-specific information such as casing rules and the alphabetic order of individual characters. For example, a culture could specify that certain combinations of characters be treated as a single character, or uppercase and lowercase characters be compared in a particular way, or that the sorting order of a character depends on the characters that precede or follow it.