次の方法で共有


String 非等値演算子

指定した 2 つの String オブジェクトの値が異なるかどうかを判断します。

returnValue = String.op_Inequality(a, b)
[C#]
public static bool operator !=(stringa,stringb);
[C++]
public: static bool op_Inequality(String* a,String* b);
[JScript]
returnValue = a != b;

[Visual Basic] Visual Basic では、この型で定義されている演算子を使用することができます。ただし、独自に定義することはできません。Equals メソッドを String 非等値演算子の代わりに使用することができます。

[JScript] JScript では、この型で定義されている演算子を使用することができます。ただし、独自に定義することはできません。

引数 [Visual Basic, JScript]

  • a
    String または null 参照 (Visual Basic では Nothing) 。
  • b
    String または null 参照 (Visual Basic では Nothing) 。

パラメータ [C#, C++]

  • a
    String または null 参照 (Visual Basic では Nothing) 。
  • b
    String または null 参照 (Visual Basic では Nothing) 。

戻り値

a の値が b の値と異なる場合は true 。それ以外の場合は false

解説

この演算子は、 Equals メソッドを使用して実装されます。つまり、比較対照値の参照と値が等しいかどうかがテストされます。比較では、大文字と小文字が区別されます。

使用例

[Visual Basic, C#, C++] 不等値演算子の例を次に示します。

 
' Example for the String Inequality operator.
Imports System
Imports Microsoft.VisualBasic

Module InequalityOp
   
    Sub Main()
        Console.WriteLine( _
            "This example of the String Inequality operator" & _
            vbCrLf & "generates the following output." & vbCrLf)

        CompareAndDisplay("ijkl")
        CompareAndDisplay("ABCD")
        CompareAndDisplay("abcd")
    End Sub 'Main
       
    Sub CompareAndDisplay(Comparand As String)

        Dim Lower As String = "abcd"
          
        Console.WriteLine( _
            """{0}"" <> ""{1}"" ?  {2}", _
            Lower, Comparand, Lower <> Comparand)

    End Sub 'CompareAndDisplay
End Module 'InequalityOp

' This example of the String Inequality operator
' generates the following output.
' 
' "abcd" <> "ijkl" ?  True
' "abcd" <> "ABCD" ?  True
' "abcd" <> "abcd" ?  False

[C#] 
// 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
*/

[C++] 
// Example for the String Inequality operator.
#using <mscorlib.dll>
using namespace System;

void CompareAndDisplay( String* Comparand )
{
    String*  Lower = S"abcd";

    Console::WriteLine( 
        S"\"{0}\" != \"{1}\" ?  {2}",
        Lower, Comparand, __box( Lower != Comparand ) );
}

void main( ) 
{
    Console::WriteLine( 
        S"This example of the String Inequality operator\n" 
        S"generates the following output.\n" );

    CompareAndDisplay( S"ijkl" );
    CompareAndDisplay( S"ABCD" );
    CompareAndDisplay( S"abcd" );
}

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

"abcd" != "ijkl" ?  True
"abcd" != "ABCD" ?  True
"abcd" != "abcd" ?  False
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

String クラス | String メンバ | System 名前空間