C# String Equals(String)

Description

String Equals(String) determines whether this instance and another specified String object have the same value.

Syntax

String.Equals(String) has the following syntax.


public bool Equals(
  string value
)

Parameters

String.Equals(String) has the following parameters.

  • value - The string to compare to this instance.

Returns

String.Equals(String) method returns true if the value of the value parameter is the same as this instance; otherwise, false.

Example

The following example demonstrates the Equals method.


using System;//from  w w  w. j  a  v  a 2 s. c om

public class Example
{
   public static void Main()
   {
      Console.OutputEncoding = System.Text.Encoding.UTF8;
      string word = "File";
      string[] others = { word.ToLower(), word, word.ToUpper(), "f1le" };
      foreach (string other in others)
      {
         if (word.Equals(other)) 
            Console.WriteLine("{0} = {1}", word, other);
         else
            Console.WriteLine("{0} {1} {2}", word, '\u2260', other);
      }        
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version