Export (0) Print
Expand All

String.op_Inequality Method

Determines whether two specified String objects have different values.

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

public static bool operator != (
	string a,
	string b
)
Not applicable.

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 different from 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 inequality operator.

// 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
*/

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

class InequalityOp
{
    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the String Inequality 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
} //InequalityOp

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

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

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft