Bagikan melalui


String.Inequality(String, String) Operator

Definisi

Menentukan apakah dua string yang ditentukan memiliki nilai yang berbeda.

public:
 static bool operator !=(System::String ^ a, System::String ^ b);
public static bool operator != (string a, string b);
public static bool operator != (string? a, string? b);
static member op_Inequality : string * string -> bool
Public Shared Operator != (a As String, b As String) As Boolean

Parameter

a
String

String pertama yang dibandingkan, atau null.

b
String

String kedua untuk dibandingkan, atau null.

Mengembalikan

true jika nilai berbeda dari a nilai b; jika tidak, false.

Contoh

Contoh berikut menunjukkan operator ketidaksamaan.

// Example for the String Inequality operator.
using namespace System;
void CompareAndDisplay( String^ Comparand )
{
   String^ Lower = "abcd";
   Console::WriteLine( "\"{0}\" != \"{1}\" ?  {2}", Lower, Comparand, Lower != Comparand );
}

int main()
{
   Console::WriteLine( "This example of the String Inequality operator\n"
   "generates the following output.\n" );
   CompareAndDisplay( "ijkl" );
   CompareAndDisplay( "ABCD" );
   CompareAndDisplay( "abcd" );
}

/*
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.
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.
printfn "This example of the String Inequality operator\ngenerates the following output.\n"

let compareAndDisplay comparand =
    let lower = "abcd"
    printfn $"\"%s{lower}\" <> \"%s{comparand}\" ?  {lower <> comparand}"

compareAndDisplay "ijkl"
compareAndDisplay "ABCD"
compareAndDisplay "abcd"

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

"abcd" <> "ijkl" ?  True
"abcd" <> "ABCD" ?  True
"abcd" <> "abcd" ?  False
*)

Keterangan

Metode ini Inequality menentukan pengoperasian operator ketidaksetaraan untuk String kelas . Ini memungkinkan kode seperti yang ditunjukkan di bagian Contoh.

Operator pada gilirannya Inequality memanggil metode statis Equals(String, String) , yang melakukan perbandingan ordinal (peka huruf besar/kecil dan budaya).

Catatan

Pengkompilasi Visual Basic tidak menyelesaikan operator ketidaksetaraan sebagai panggilan ke Inequality metode . Sebaliknya, operator ketidaksamaan membungkus panggilan ke Operators.CompareString metode .

Berlaku untuk