CSharp · Console
// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002162/string-intern
// @nuget: Z.ExtensionMethods
using System;
using System.Text;
public class Program
{
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);
}
}