Intern a String in CSharp
Description
The following code shows how to intern a String.
Example
//from w ww . j ava 2 s. com
using System;
public class StringInterning
{
public static void Main()
{
string s1 = "Hello";
string s2 = "Hello";
string s3 = "Hello".Substring(0, 4) + "o";
Console.WriteLine("Str == : {0}", s1 == s2);
Console.WriteLine("Ref == : {0}", (object) s1 == (object) s2);
Console.WriteLine("Str == : {0}", s1 == s3);
Console.WriteLine("Ref == : {0}", (object) s1 == (object) s3);
}
}
The code above generates the following result.