想知道为什么String在使用==时表现得像值类型.
String s1 = "Hello"; String s2 = "Hello"; Console.WriteLine(s1 == s2);// True(why? s1 and s2 are different) Console.WriteLine(s1.Equals(s2));//True StringBuilder a1 = new StringBuilder("Hi"); StringBuilder a2 = new StringBuilder("Hi"); Console.WriteLine(a1 == a2);//false Console.WriteLine(a1.Equals(a2));//true
StringBuilder和String的行为与==运算符不同.
谢谢.