Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String Inequality Operator

Determines whether two specified String objects have different values.

[Visual Basic]
returnValue = String.op_Inequality(a, b)
[C#]
public static bool operator !=(
 string a,
 string b
);
[C++]
public: static bool op_Inequality(
 String* a,
 String* b
);
[JScript]
returnValue = a != b;

[Visual Basic] In Visual Basic, you can use the operators defined by a type, but you cannot define your own. You can use the Equals method instead of the String inequality operator.

[JScript] In JScript, you can use the operators defined by a type, but you cannot define your own.

Arguments [Visual Basic, JScript]

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

Parameters [C#, C++]

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 different from the value of b; otherwise, false.

Remarks

This operator is implemented using the Equals method, which means the comparands are tested for a combination of reference and value equality. The comparison is case-sensitive.

Example

[Visual Basic, C#, C++] The following example demonstrates the inequality operator.

[Visual Basic] 
' Example for the String Inequality operator.
Imports System
Imports Microsoft.VisualBasic

Module InequalityOp
   
    Sub Main()
        Console.WriteLine( _
            "This example of the String Inequality 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 'InequalityOp

' This example of the String Inequality operator
' generates the following output.
' 
' "abcd" <> "ijkl" ?  True
' "abcd" <> "ABCD" ?  True
' "abcd" <> "abcd" ?  False

[C#] 
// Example for the String Inequality operator.
using System;

class InequalityOp 
{
    public static void Main() 
    {
        Console.WriteLine( 
            "This example of the String Inequality operator\n" +
            "generates the following output.\n" );

        CompareAndDisplay( "ijkl" );
        CompareAndDisplay( "ABCD" );
        CompareAndDisplay( "abcd" );
    }

    static void CompareAndDisplay( String Comparand )
    {
        String  Lower = "abcd";

        Console.WriteLine( 
            "\"{0}\" != \"{1}\" ?  {2}",
            Lower, Comparand, Lower != Comparand );
    }
}

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

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

[C++] 
// Example for the String Inequality operator.
#using <mscorlib.dll>
using namespace System;

void CompareAndDisplay( String* Comparand )
{
    String*  Lower = S"abcd";

    Console::WriteLine( 
        S"\"{0}\" != \"{1}\" ?  {2}",
        Lower, Comparand, __box( Lower != Comparand ) );
}

void main( ) 
{
    Console::WriteLine( 
        S"This example of the String Inequality operator\n" 
        S"generates the following output.\n" );

    CompareAndDisplay( S"ijkl" );
    CompareAndDisplay( S"ABCD" );
    CompareAndDisplay( S"abcd" );
}

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

String Class | String Members | System Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft