String.Equality(String, String) 연산자

정의

지정된 두 문자열의 값이 같은지를 확인합니다.

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 ( = ) : string * string -> bool
Public Shared Operator == (a As String, b As String) As Boolean

매개 변수

a
String

비교할 첫 번째 문자열 또는 null입니다.

b
String

비교할 두 번째 문자열 또는 null입니다.

반환

Boolean

true의 값이 a의 값과 같으면 b이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 같음 연산자를 보여줍니다.

// 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 정의합니다. 예제 섹션에 표시된 와 같은 코드를 사용하도록 설정합니다. 연산자는 Equals(String, String) 서수(대/소문자 구분 및 문화권 구분 안 함) 비교를 수행하는 정적 메서드를 호출합니다.

참고

Visual Basic 컴파일러가 같음 연산자를 메서드 호출로 해결하지 Equality 않습니다. 대신 같음 연산자는 메서드에 대한 호출을 Operators.CompareString 래핑합니다.

적용 대상