指定した 2 つの String オブジェクトの値が同一かどうかを判断します。
returnValue = String.op_Equality(a, b)
[C#]
public static bool operator ==(stringa,stringb);
[C++]
public: static bool op_Equality(String* a,String* b);
[JScript]
returnValue = a == b;
[Visual Basic] Visual Basic では、この型で定義されている演算子を使用することができます。ただし、独自に定義することはできません。Equals メソッドを String 等値演算子の代わりに使用することができます。
[JScript] JScript では、この型で定義されている演算子を使用することができます。ただし、独自に定義することはできません。
引数 [Visual Basic, JScript]
パラメータ [C#, C++]
戻り値
a の値が b の値と同じ場合は true 。それ以外の場合は false 。
解説
この演算子は、 Equals メソッドを使用して実装されます。つまり、比較対照値の参照と値が等しいかどうかがテストされます。比較では、大文字と小文字が区別されます。
使用例
[Visual Basic, C#, C++] 等値演算子の例を次に示します。
' Example for the String Equality operator.
Imports System
Imports Microsoft.VisualBasic
Module EqualityOp
Sub Main()
Console.WriteLine( _
"This example of the String Equality 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 'EqualityOp
' This example of the String Equality operator
' generates the following output.
'
' "abcd" = "ijkl" ? False
' "abcd" = "ABCD" ? False
' "abcd" = "abcd" ? True
[C#]
// 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
*/
[C++]
// Example for the String Equality 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 Equality operator\n"
S"generates the following output.\n" );
CompareAndDisplay( S"ijkl" );
CompareAndDisplay( S"ABCD" );
CompareAndDisplay( S"abcd" );
}
/*
This example of the String Equality operator
generates the following output.
"abcd" == "ijkl" ? False
"abcd" == "ABCD" ? False
"abcd" == "abcd" ? True
*/
[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