Why in this situation ReferenceEquals
method of object behaves differently?
string a= "fg";
string b= "fg";
Console.WriteLine(object.ReferenceEquals(a, b));
So in this situation it's get a result true
. In case, it compares values of my strings and not references. But when I write something like:
StringBuilder c = new StringBuilder("fg");
string d = c.ToString();
Console.WriteLine(object.ReferenceEquals(a, d));
In this case it works fine and result is false
, because it compares references of my objects.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…