String - Intern

Retrieves the system's reference to the specified String.

Try it

public static void Main()
{
    String s1 = "MyTest";
	String s2 = new StringBuilder().Append("My").Append("Test").ToString();
	
	// C# Extension Method: String - Intern
	String s3 = s2.Intern();
	
	Console.WriteLine("s1 == '{0}'", s1);
	Console.WriteLine("s2 == '{0}'", s2);
	Console.WriteLine("s3 == '{0}'", s3);
	Console.WriteLine("Is s2 the same reference as s1?: {0}", (Object)s2==(Object)s1); 
	Console.WriteLine("Is s3 the same reference as s1?: {0}", (Object)s3==(Object)s1);
	
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Retrieves the system&#39;s reference to the specified .
    /// </summary>
    /// <param name="str">A string to search for in the intern pool.</param>
    /// <returns>
    ///     The system&#39;s reference to , if it is interned; otherwise, a new reference to a string with the value of .
    /// </returns>
    public static String Intern(this String str)
    {
        return String.Intern(str);
    }
}