nik*_*tix 2 c# string comparison
我用C#搞砸了一下,发现了一个非常不舒服的代码:
static void Main(string[] args)
{
string a = "string", b = "string\0";
bool b1 = a == b;
bool b2 = (a.CompareTo(b) > 0);
bool b3 = (a.CompareTo(b) < 0);
bool b4 = (a.CompareTo(b) == 0);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine("{0} {1} {2} {3}", b1, b2, b3, b4);
}
Run Code Online (Sandbox Code Playgroud)
输出:
string
string
False False False True
Run Code Online (Sandbox Code Playgroud)
预期产出(上):
string
string
True False False True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
94 次 |
| 最近记录: |