我使用这段代码,得到了正确的结果:
object text1 = "test";
object text2 = "test";
Console.WriteLine("text1 == text2 : " + (text1 == text2));
//return:true
但是当我尝试将其转换为小写时:object text2 = "test".ToLower();
我得到了false
的结果?
object text1 = "test".ToLower();
object text2 = "test".ToLower();
Console.WriteLine("text1 == text2 : " + (text1 == text2));
//return:false
==
确实是针对引用的。 - Andre CalilString.Equality
是使用值相等性的,但是Object.Equals
使用引用相等性,这就是我所说的。 - Reed Copsey