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 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
*)
備註
方法 Inequality 會定義 類別的不等比較運算子 String 運算。 它會啟用程式碼,例如 [範例] 區段中所示的程式碼。
運算子 Inequality 接著會呼叫靜態 Equals(String, String) 方法,它會執行區分大小寫且不區分文化特性的序數 () 比較。
注意
Visual Basic 編譯器不會將不等比較運算子解析為方法的 Inequality 呼叫。 相反地,不等比較運算子會包裝方法的 Operators.CompareString 呼叫。