问题描述
我测试了string.compare()并得到以下结果.有人可以验证吗?
``-''(破折号/减号)的ascii值为45.
0(零)的ascii值为48.
因此,-"小于任何数字.
每个测试应返回-1,但结果如下:
1. string.Compare(-1","2")返回-1
2. string.Compare(-2","2")返回1
3. string.Compare(-3","2")返回1
4. string.Compare(-1","22")返回-1
5. string.Compare(-2","22")返回-1
6. string.Compare(-3","22")返回1
似乎C#在比较时会忽略-".但是,如果是这样,则测试#2应该返回0.
I tested the string.compare() and got the following results. Can anyone verify it?
''-'' (dash/minus) has an ascii value of 45.
0 (zero) has ascii value of 48.
Therefore, ''-'' is less than any numeral digit.
Each test should return -1, but they comes out as below:
1. string.Compare("-1","2") returns -1
2. string.Compare("-2","2") returns 1
3. string.Compare("-3","2") returns 1
4. string.Compare("-1","22") returns -1
5. string.Compare("-2","22") returns -1
6. string.Compare("-3","22") returns 1
Seem like C# ignores the ''-'' when it compares. However, if that is true, then test #2 should return 0.
推荐答案
这篇关于字符串为负的String.Compare()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!