Determines whether this instance and a specified object, which must also be a string object, have the same value.
true if obj is a string and its value is the same as this instance; otherwise, false.
Type Reason NullReferenceException The current instance is a null reference.
The following example demonstrates checking to see if an object is equal to the current instance.
C# Example
using System; public class StringEqualsExample { public static void Main() { string str = "A string"; Console.WriteLine( "The given string is '{0}'", str ); Console.Write( "The given string is equal to 'A string'? " ); Console.WriteLine( str.Equals( "A string" ) ); Console.Write( "The given string is equal to 'A String'? " ); Console.WriteLine( str.Equals( "A String" ) ); } }
The output is
The given string is 'A string'