CLR maintains a hashtable (intern pool ) to stores literals in it lets say �Anand� , the prime reason is to conserve memory and this is shared across all app domains in the same process .The runtime add the literals into the hashtable when a method is jited as below<o:p></o:p>
<o:p> </o:p>
static void <st1:place w:st="on">Main</st1:place>(string[] args)<o:p></o:p>
{<o:p></o:p>
string str1 ="Anand";<o:p></o:p>
string str2 = "Anand";<o:p></o:p>
if(object.ReferenceEquals(str1,str2))<o:p></o:p>
{<o:p></o:p>
Console.WriteLine("Both are share the same memory");<o:p></o:p>
}<o:p></o:p>
Console.ReadLine();<o:p></o:p>
}<o:p></o:p>
<o:p> </o:p>
Remember if the string is concatenated the it will not add to the pool as below<o:p></o:p>
<o:p> </o:p>
string str1 ="Anand";<o:p></o:p>
string str2 = "Kumar";<o:p></o:p>
String str3 = str1+str2;<o:p></o:p>
<o:p></o:p>
if(object.ReferenceEquals(str3,"AnandKumar"))<o:p></o:p>
{<o:p></o:p>
Console.WriteLine("Both are share the same memory");<o:p></o:p>
}<o:p></o:p>
Console.ReadLine();<o:p></o:p>
Note : str3 is constructed at runtime so its returns false .<o:p></o:p>
<o:p> </o:p>
You can add the string to the pool at runtime by calling String.Intern<o:p></o:p>
As below<o:p></o:p>
<o:p> </o:p>
static void <st1:place w:st="on">Main</st1:place>(string[] args)<o:p></o:p>
{<o:p></o:p>
string str1 ="Anand";<o:p></o:p>
string str2 = "Kumar";<o:p></o:p>
String str3 = String.Intern(str1+str2);<o:p></o:p>
<o:p></o:p>
if(object.ReferenceEquals(str3,"AnandKumar"))<o:p></o:p>
{<o:p></o:p>
Console.WriteLine("Both are share the same memory");<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
<o:p> </o:p>
Once again the main point is why this is not applicable to every type, that�s a million dollars question the answer is it applicable to immutable types such as string object.<o:p></o:p>
<o:p> </o:p>
<o:p>Cheers</o:p>
<o:p>Anand</o:p>