我弄乱用C#一点,发现产生非常不舒服的结果的代码:C#字符串:为什么字符串a == b运算符给出与a.CompareTo(b)== 0不同的答案?
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);
}
输出:
string
string
False False False True
预期输出(的):
string
string
True False False True
您可以编辑您的文章,并添加您预期的输出? –