String.Equals Method (String)

May 11, 2014

Determines whether this instance and another specified String object have the same value.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public bool Equals(
	string value
)

Parameters

value
Type: System.String
The string to compare to this instance.

Return Value

Type: System.Boolean
true if the value of the value parameter is the same as this instance; otherwise, false.

Implements

IEquatable<T>.Equals(T)

This method performs an ordinal (case-sensitive and culture-insensitive) comparison.

The following example demonstrates the Equals(String) method.


using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string word = "File";
      string[] others = { word.ToLower(), word, word.ToUpper(), "fıle" };
      foreach (string other in others)
      {
         if (word.Equals(other))
            outputBlock.Text += String.Format("{0} = {1}", word, other) + "\n";
         else
            outputBlock.Text += String.Format("{0} {1} {2}", word, '\u2260', other) + "\n";
      }
   }
}
// The example displays the following output:
//       File ≠ file
//       File = File
//       File ≠ FILE
//       File ≠ fıle


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft