我弄亂用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
您可以編輯您的文章,並添加您預期的輸出? –