As indicated here, a string that is created at runtime cannot be interned.
However, the following code:
class Program {
static void Main(string[] args)
{
string s1 = "Programming Is Fun";
string s3 = s1.ToString();
Console.WriteLine(Object.ReferenceEquals(s1, s3));
}
}
gives (VS 2015):
True
So, is it specified somehow which strings are generated in runtime?
BTW:
The code:
using System;
using System.Text;
class Program {
static void Main(string[] args)
{
string s1 = "hop";
StringBuilder s2 = new StringBuilder(s1);
string s3 = s2.ToString();
Console.WriteLine(Object.ReferenceEquals(s1, s3));
}
}
gives (VS 2015):
False
in opposite to mono (ver. 4.0.2) which gives
True
see the working example.