String.Inequality(String, String) String.Inequality(String, String) String.Inequality(String, String) String.Inequality(String, String) Operator

定義

判斷兩個指定的字串是否具有不同的值。Determines whether two specified strings have different values.

public:
 static bool operator !=(System::String ^ a, System::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 String String String

要比較的第一個字串,或是 nullThe first string to compare, or null.

b
String String String String

要比較的第二個字串,或 nullThe second string to compare, or null.

傳回

如果 true 的值與 a 的值不同,則為 b,否則為 falsetrue if the value of a is different from the value of b; otherwise, false.

範例

下列範例示範不等比較運算子。The following example demonstrates the inequality operator.

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

備註

方法會定義String類別之不等比較運算子的運算。 InequalityThe Inequality method defines the operation of the inequality operator for the String class. 它會啟用如範例一節所示的程式碼。It enables code such as that shown in the Examples section.

運算子接著會呼叫靜態Equals(String, String)方法,它會執行序數(區分大小寫且不區分文化特性)的比較。 InequalityThe Inequality operator in turn calls the static Equals(String, String) method, which performs an ordinal (case-sensitive and culture-insensitive) comparison.

注意

Visual Basic 編譯器不會將不等比較運算子解析為Inequality方法的呼叫。The Visual Basic compiler does not resolve the inequality operator as a call to the Inequality method. 相反地Operators.CompareString ,不等比較運算子會包裝對方法的呼叫。Instead, the inequality operator wraps a call to the Operators.CompareString method.

適用於