I know what string interning is and why the following code behaves like this:
var hello = "Hello"; var he_llo = "He" + "llo"; var b = ReferenceEquals(hello, he_llo);
or
var hello = "Hello"; var h_e_l_l_o = new string(new char[] { 'H', 'e', 'l', 'l', 'o' }); var b = ReferenceEquals(hello, he_llo);
... or I thought I did, because because of this, I found a subtle error in some code, because of which I work:
var s = ""; var sss = new string(new char[] { }); var b = ReferenceEquals(s, sss);
How does the compiler know that sss
will actually be an empty string?
source share