String.Equals Method (String)

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

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

Syntax

'Declaration
Public Function Equals ( _
    value As String _
) As Boolean
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)

Remarks

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

Examples

The following example demonstrates the Equals(String) method.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim word As String = "File"
      Dim others() As String = {word.ToLower(), word, word.ToUpper(), _
                                 "fıle"}
      For Each other As String In others
         If word.Equals(other) Then
            outputBlock.Text += String.Format("{0} = {1}", word, other) & vbCrLf
         Else
            outputBlock.Text += String.Format("{0} {1} {2}", word, ChrW(&H2260), other) & vbCrLf
         End If
      Next
   End Sub
End Module
' The example displays the following output:
'       File ≠ file
'       File = File
'       File ≠ FILE
'       File ≠ fıle
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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.