private static void WriteInternmentExample() { Console.WriteLine("Examples of internment."); Console.WriteLine("Without internment:"); var s1 = CustomString.CreateInstance("Hello world".ToCharArray()); Console.WriteLine($"{nameof(s1)} = \"{s1}\" created..."); var s2 = CustomString.CreateInstance("Hello world".ToCharArray()); Console.WriteLine($"{nameof(s2)} = \"{s2}\" created..."); Console.WriteLine($"{nameof(s1)}.Equals({nameof(s2)}) => {s1.Equals(s2)}"); Console.WriteLine($"ReferenceEquals({nameof(s1)},{nameof(s2)}) => {ReferenceEquals(s1, s2)}"); Console.WriteLine(); Console.WriteLine("With internment:"); var s3 = CustomString.CreateInstance("Hello world".ToCharArray()); Console.WriteLine($"{nameof(s3)} = \"{s3}\" created..."); s3 = CustomString.Intern(s3); Console.WriteLine($"{nameof(s3)} = \"{s3}\" interned..."); var s4 = CustomString.CreateInstance("Hello world".ToCharArray()); Console.WriteLine($"{nameof(s4)} = \"{s4}\" created..."); Console.WriteLine($"{nameof(s3)}.Equals({nameof(s4)}) => {s3.Equals(s4)}"); Console.WriteLine($"ReferenceEquals({nameof(s3)},{nameof(s4)}) => {ReferenceEquals(s3, s4)}"); WriteSeparatorStringsAndAwaitMessage(); }