String.Equality(String, String) String.Equality(String, String) String.Equality(String, String) String.Equality(String, String) Operator

定義

指定した 2 つの文字列の値が同一かどうかを判断します。 Determines whether two specified strings have the same value.

public:
 static bool operator ==(System::String ^ a, System::String ^ b);
public static bool operator == (string a, string b);
static member ( = ) : string * string -> bool
Public Shared Operator == (a As String, b As String) As Boolean
パラメーター
a
String String String String

比較する最初の文字列または null The first string to compare, or null.

b
String String String String

比較する 2 番目の文字列または null The second string to compare, or null.

戻り値

a の値が b の値と同じ場合は true。それ以外の場合は false true if the value of a is the same as the value of b; otherwise, false.

次の例では、等値演算子を示します。The following example demonstrates the equality operator.

// Example for the String Equality 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 Equality operator\n"
   "generates the following output.\n" );
   CompareAndDisplay( "ijkl" );
   CompareAndDisplay( "ABCD" );
   CompareAndDisplay( "abcd" );
}

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

"abcd" == "ijkl" ?  False
"abcd" == "ABCD" ?  False
"abcd" == "abcd" ?  True
*/
// Example for the String Equality operator.
using System;

class EqualityOp 
{
    public static void Main() 
    {
        Console.WriteLine( 
            "This example of the String Equality 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 Equality operator 
generates the following output.

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

注釈

Equalityメソッド定義の等値演算子の操作、Stringクラス。The Equality method defines the operation of the equality operator for the String class. 「使用例に示すように示すようなコードができるようにします。It enables code such as that shown in the Example section. 演算子をさらに、静的なを呼び出すEquals(String, String)メソッドで、序数に基づく (大文字と小文字およびカルチャに依存しない) 比較を実行します。The operator, in turn, calls the static Equals(String, String) method, which performs an ordinal (case-sensitive and culture-insensitive) comparison.

注意

Visual Basic コンパイラでも、等値演算子の呼び出しとして解決しない、Equalityメソッド。The Visual Basic compiler does not resolve the equality operator as a call to the Equality method. 等値演算子がへの呼び出しをラップする代わりに、Operators.CompareStringメソッド。Instead, the equality operator wraps a call to the Operators.CompareString method.

適用対象