string s1 = "abc";
string s2 = "ab";
string s3 = s2 + "c";
Console.WriteLine(string.IsInterned(s3)); // abc
Console.WriteLine(String.ReferenceEquals(s1, s3)); // False
I just cannot understand why s3 interned, but ReferenceEquals
was False.
Dose they have two copies in intern pool?
Thanks in advance.
They are separate references. The string "abc"
is interned because it is a literal string.
The expression s2 + "c"
is compiled to string.Concat(s2, "c")
.. which results in a new (and separate) string reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With