Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

String.op_Equality Method

Determines whether two specified String objects have the same value.

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

'Declaration
Public Shared Operator = ( _
	a As String, _
	b As String _
) As Boolean
'Usage
Dim a As String
Dim b As String
Dim returnValue As Boolean

returnValue = (a = b)
J# does not support overloaded operators.
JScript supports the use of overloaded operators, but not the declaration of new ones.

Parameters

a

A String or a null reference (Nothing in Visual Basic).

b

A String or a null reference (Nothing in Visual Basic).

Return Value

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

This operator is implemented using the Equals method, which means the comparands are tested for a combination of reference and value equality. This operator performs an ordinal comparison.

The following code example demonstrates the equality operator.

' Example for the String Equality operator.
Imports System
Imports Microsoft.VisualBasic

Module EqualityOp
       
    Sub Main()
        Console.WriteLine( _
            "This example of the String Equality operator " & vbCrLf & _
            "generates the following output." & vbCrLf)

        CompareAndDisplay("ijkl")
        CompareAndDisplay("ABCD")
        CompareAndDisplay("abcd")
    End Sub 'Main
       
    Sub CompareAndDisplay(Comparand As String)
        Dim Lower As String = "abcd"
          
        Console.WriteLine( _
            """{0}"" = ""{1}"" ?  {2}", _
            Lower, Comparand, Lower = Comparand)

    End Sub 'CompareAndDisplay
End Module 'EqualityOp

' This example of the String Equality operator 
' generates the following output.
'
' "abcd" = "ijkl" ?  False
' "abcd" = "ABCD" ?  False
' "abcd" = "abcd" ?  True

// Example for the String Equality operator.
import System.*;

class EqualityOp
{
    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the String Equality operator\n" 
            + "generates the following output.\n"));
        CompareAndDisplay("ijkl");
        CompareAndDisplay("ABCD");
        CompareAndDisplay("abcd");
    } //main

    static void CompareAndDisplay(String comparand)
    {
        String lower = "abcd";
        Console.WriteLine("\"{0}\" == \"{1}\" ?  {2}", lower, comparand, 
            System.Convert.ToString(lower.equals(comparand)));
    } //CompareAndDisplay
} //EqualityOp

/*
This example of the String Equality operator 
generates the following output.

"abcd" == "ijkl" ?  False
"abcd" == "ABCD" ?  False
"abcd" == "abcd" ?  True
*/

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.