string.Compare 行为

发布于 2024-08-14 12:08:50 字数 120 浏览 3 评论 0原文

怎么会这样呢? (这是从VS2008中的立即窗口获取的)

?string.Compare("-", "+")
-1
?string.Compare("-0", "+0")
1

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

?string.Compare("-", "+")
-1
?string.Compare("-0", "+0")
1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆萌少年 2024-08-21 12:08:50

来自 String.Compare 的评论(强调我的):

比较使用当前区域性来获取特定于区域性的信息,例如大小写规则和单个字符的字母顺序。例如,区域性可以指定将某些字符组合视为单个字符,或者以特定方式比较大写和小写字符,或者字符的排序顺序取决于前面或后面的字符它。

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.

原谅过去的我 2024-08-21 12:08:50

C#手册写道:

比较使用当前
文化以获得特定文化
诸如大小写规则等信息
个人的字母顺序
人物。例如,一种文化
可以指定某些
待处理的字符组合
作为单个字符或大写
和小写字符进行比较
以某种特定的方式,或者说
字符的排序顺序取决于
在 或 之前的字符上
跟着它。

使用word进行比较
排序规则。欲了解更多信息
单词、字符串和序数排序,请参阅
System.Globalization.CompareOptions

The C# manual writes:

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.

The comparison is performed using word
sort rules. For more information about
word, string, and ordinal sorts, see
System.Globalization.CompareOptions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文