I was sure that this would output false, but actually it outputs true:
string foo = new string("foo".ToCharArray());
Console.WriteLine(string.IsInterned(foo) != null); // true
I thought that creating it already via constructor would prevent string interning. But even using a char[]
causes it to be interned. What is the reason or what is my error in reasoning?
Literal strings are interned. And you have the literal foo
in your source code.