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.

반품

값이 값 과 같으면 입니다. 그렇지 않으면 .

예제

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

// 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
*/
// Example for the String Equality operator.
printfn "This example of the String Equality 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 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 래핑합니다.

적용 대상