Mono Class Library: System.String Overview | Members

System.String.Equals Method

Determines whether two specified string objects have the same value. [Edit]

public static bool Equals (string a, string b)

Parameters

a
A string or a null reference. [Edit]
b
A string or a null reference. [Edit]

Returns

true if the value of a is the same as the value of b; otherwise, false. [Edit]

Remarks

The comparison is case-sensitive. [Edit]

Example

The following example demonstrates checking to see if two strings are equal.

C# Example
using System;
public class StringEqualsExample {
 public static void Main() {
 string strA = "A string";
 string strB = "a string";
 string strC = "a string";
 Console.Write( "The string '{0}' is equal to the string '{1}'? ", strA, strB );
 Console.WriteLine( String.Equals( strA, strB ) );
 Console.Write( "The string '{0}' is equal to the string '{1}'? ", strC, strB );
 Console.WriteLine( String.Equals( strC, strB ) );
 }
}
   

The output is

The string 'A string' is equal to the string 'a string'? False
The string 'a string' is equal to the string 'a string'? True

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0