Going deeper in C#, I have encountered a little (strange) problem with object reference equality.
Let says I have two strings:
String a = "Hello world!";
String b = "Bonjour le monde";
bool equals = ReferenceEquals(a, b); // ******************* (1)
b = "Hello world!";
equals = ReferenceEquals(a, b); // ******************* (2)
(1)
Is false
and that is expected.
ReferenceEquals Documentation says
ReferenceEquals compares instances
but then:
- Why does (2) returns
true
?
- Strings
a
and b
are not the same object are they? If yes then how did they become the same given that I never explicitly did a=b
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…