This returns true because the CLR uses string interning to optimize
string handling.
Actually it seems to work even if the strings aren't interned, suggesting it
is instead a "I didn't update anything, return the original reference"
optimisation; since it is an internal-call, it is hard to check...
Anyways, s1 and s2 come out as ref-equals, even though it isn't interned.
Marc
string s0 = "foobar"; // expect this to be interned
Console.WriteLi ne("s0: {0}", s0);
Console.WriteLi ne("s0 interned: {0}", (string.IsInter ned(s0) !=
null));
string s1 = new string('a',5); // don't expect this to be
interned
Console.WriteLi ne("s1: {0}", s1);
Console.WriteLi ne("s1 interned: {0}", (string.IsInter ned(s1) !=
null));
string s2 = s1.Replace("b", "c");
Console.WriteLi ne("s2: {0}", s1);
Console.WriteLi ne("ref-equals: {0}", object.Referenc eEquals(s1,
s2));
Console.WriteLi ne("s1 interned: {0}", (string.IsInter ned(s1) !=
null));
Console.WriteLi ne("s2 interned: {0}", (string.IsInter ned(s2) !=
null));