From the msdn documentation of the .ReferenceEquals object here :
When comparing strings. If objA and objB are strings, the ReferenceEquals method returns true if the string is interned. It does not check for equality of values. In the following example, s1 and s2 are equal since they are two instances of the same interned string. However, s3 and s4 are not equal, because although they have the same string values, this string is not interned.
using System; public class Example { public static void Main() { String s1 = "String1"; String s2 = "String1"; Console.WriteLine("s1 = s2: {0}", Object.ReferenceEquals(s1, s2)); Console.WriteLine("{0} interned: {1}", s1, String.IsNullOrEmpty(String.IsInterned(s1)) ? "No" : "Yes"); String suffix = "A"; String s3 = "String" + suffix; String s4 = "String" + suffix; Console.WriteLine("s3 = s4: {0}", Object.ReferenceEquals(s3, s4)); Console.WriteLine("{0} interned: {1}", s3, String.IsNullOrEmpty(String.IsInterned(s3)) ? "No" : "Yes"); } }
source share