C# String Equals(Object)
Description
String Equals(Object)
determines whether this instance
and a specified object, which must also be a String object, have the same value.
Syntax
String.Equals(Object)
has the following syntax.
public override bool Equals(
Object obj
)
Parameters
String.Equals(Object)
has the following parameters.
obj
- The string to compare to this instance.
Returns
String.Equals(Object)
method returns true if obj is a String and its value is the same as this instance; otherwise,
false.
Example
The following example demonstrates the Equals method.
/*from w w w. j a v a 2s . co m*/
using System;
using System.Text;
class Sample {
public static void Main() {
StringBuilder sb = new StringBuilder("abcd");
String str1 = "abcd";
String str2 = null;
Object o2 = null;
Console.WriteLine(" Is str1 equal to sb?: {0}", str1.Equals(sb));
}
}
The code above generates the following result.