String.Equality(String, String) Operator
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した 2 つの文字列の値が同じかどうかを判断します。
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
比較する 2 番目の文字列( 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) メソッドを呼び出し、序数 (大文字と小文字が区別され、カルチャに依存しない) 比較を実行します。
Note
Visual Basic コンパイラは、等値演算子を Equality メソッドの呼び出しとして解決しません。 代わりに、等値演算子は、 Operators.CompareString メソッドの呼び出しをラップします。