String.Inequality(String, String) Operator

定義

指定した 2 つの文字列の値が異なるかどうかを判断します。

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

パラメーター

a
String

比較する最初の文字列( null)。

b
String

比較する 2 番目の文字列( null)。

返品

true aの値がbの値と異なる場合は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
*)

注釈

Inequality メソッドは、String クラスの不等値演算子の操作を定義します。 [例] セクションに示すようなコードが有効になります。

Inequality演算子は、静的なEquals(String, String) メソッドを呼び出し、序数 (大文字と小文字が区別され、カルチャに依存しない) 比較を実行します。

Note

Visual Basic コンパイラは、Inequality メソッドの呼び出しとして不等値演算子を解決しません。 代わりに、等しくない演算子は、 Operators.CompareString メソッドの呼び出しをラップします。

適用対象