class Program
{
static void Main(string[] args)
{
internPool();
Console.Read();
}
//http://www.cnblogs.com/instance/archive/2011/05/24/2056091.html
static void internPool()//clr string 字符串驻留池机制,字面量字符串使用这个机制来节省内存
{
// clr初始化时会自动初始化 string.empty字符串,放到clr的字符串驻留池中
Console.WriteLine(string.IsInterned(string.Empty) != null);
Console.WriteLine(string.IsInterned("") != null);
Console.WriteLine();
var s1 = "hello";
var s2 = "hello";
Console.WriteLine(object.ReferenceEquals(s1,s2));//true
var sb = new StringBuilder().Append("he").Append("llo");
Console.WriteLine(object.ReferenceEquals(s1,sb.ToString()));//falae
Console.WriteLine(object.ReferenceEquals(s1,string.Intern(sb.ToString())));//true
var s3 = "";
var s4 = string.Empty;
Console.WriteLine(object.ReferenceEquals(s3,s4));//true
}
}