String.Inequality(String, String) 運算子
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷兩個指定字串的值是否不同。
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
第二串比較,或 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 方法。