String.Equals メソッドとは? わかりやすく解説

String.Equals メソッド (String, String)

指定した 2 つString オブジェクトの値が同一かどうか判断します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
使用例使用例

Equals メソッドコード例次に示します

' Sample for String.Equals(Object)
'            String.Equals(String)
'            String.Equals(String, String)
Imports System
Imports System.Text

Class Sample
   Public Shared Sub Main()
      Dim sb As New StringBuilder("abcd")
      Dim str1 As [String] = "abcd"
      Dim str2 As [String] = Nothing
      Dim o2 As [Object] = Nothing
      
      Console.WriteLine()
      Console.WriteLine(" *  The value of String
 str1 is '{0}'.", str1)
      Console.WriteLine(" *  The value of StringBuilder sb
 is '{0}'.", sb.ToString())
      
      Console.WriteLine()
      Console.WriteLine("1a) String.Equals(Object). Object is
 a StringBuilder, not a String.")
      Console.WriteLine("    Is str1 equal to sb?: {0}",
 str1.Equals(sb))
      
      Console.WriteLine()
      Console.WriteLine("1b) String.Equals(Object). Object is
 a String.")
      str2 = sb.ToString()
      o2 = str2
      Console.WriteLine(" *  The value of Object
 o2 is '{0}'.", o2)
      Console.WriteLine("    Is str1 equal to o2?: {0}",
 str1.Equals(o2))
      
      Console.WriteLine()
      Console.WriteLine(" 2) String.Equals(String)")
      Console.WriteLine(" *  The value of String
 str2 is '{0}'.", str2)
      Console.WriteLine("    Is str1 equal to str2?: {0}",
 str1.Equals(str2))
      
      Console.WriteLine()
      Console.WriteLine(" 3) String.Equals(String, String)")
      Console.WriteLine("    Is str1 equal to str2?: {0}",
 [String].Equals(str1, str2))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
' *  The value of String str1 is 'abcd'.
' *  The value of StringBuilder sb is 'abcd'.
'
'1a) String.Equals(Object). Object is a StringBuilder, not a String.
'    Is str1 equal to sb?: False
'
'1b) String.Equals(Object). Object is a String.
' *  The value of Object o2 is 'abcd'.
'    Is str1 equal to o2?: True
'
' 2) String.Equals(String)
' *  The value of String str2 is 'abcd'.
'    Is str1 equal to str2?: True
'
' 3) String.Equals(String, String)
'    Is str1 equal to str2?: True
'
// Sample for String.Equals(Object)
//            String.Equals(String)
//            String.Equals(String, String)
using System;
using System.Text;

class Sample {
    public static void Main()
 {
    StringBuilder sb = new StringBuilder("abcd");
    String      str1 = "abcd";
    String      str2 = null;
    Object    o2   = null;

    Console.WriteLine();
    Console.WriteLine(" *  The value of String str1 is '{0}'.", str1);
    Console.WriteLine(" *  The value of StringBuilder sb is '{0}'.", sb.ToString());

    Console.WriteLine();
    Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder,
 not a String.");
    Console.WriteLine("    Is str1 equal to sb?: {0}", str1.Equals(sb));

    Console.WriteLine();
    Console.WriteLine("1b) String.Equals(Object). Object is a String.");
    str2 = sb.ToString();
    o2   = str2;
    Console.WriteLine(" *  The value of Object o2 is '{0}'.", o2);
    Console.WriteLine("    Is str1 equal to o2?: {0}", str1.Equals(o2));

    Console.WriteLine();
    Console.WriteLine(" 2) String.Equals(String)");
    Console.WriteLine(" *  The value of String str2 is '{0}'.", str2);
    Console.WriteLine("    Is str1 equal to str2?: {0}", str1.Equals(str2));

    Console.WriteLine();
    Console.WriteLine(" 3) String.Equals(String, String)");
    Console.WriteLine("    Is str1 equal to str2?: {0}", String.Equals(str1,
 str2));
    }
}
/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String.Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String.Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String.Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String.Equals(String, String)
    Is str1 equal to str2?: True
*/
// Sample for String::Equals(Object)
//            String::Equals(String)
//            String::Equals(String, String)
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder( "abcd" );
   String^ str1 = "abcd";
   String^ str2 = nullptr;
   Object^ o2 = nullptr;
   Console::WriteLine();
   Console::WriteLine( " *  The value of String str1 is '{0}'.", str1 );
   Console::WriteLine( " *  The value of StringBuilder sb is '{0}'.", sb
 );
   Console::WriteLine();
   Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder,
 not a String." );
   Console::WriteLine( "    Is str1 equal to sb?: {0}", str1->Equals(
 sb ) );
   Console::WriteLine();
   Console::WriteLine( "1b) String::Equals(Object). Object is a String."
 );
   str2 = sb->ToString();
   o2 = str2;
   Console::WriteLine( " *  The value of Object o2 is '{0}'.", o2 );
   Console::WriteLine( "    Is str1 equal to o2?: {0}", str1->Equals(
 o2 ) );
   Console::WriteLine();
   Console::WriteLine( " 2) String::Equals(String)" );
   Console::WriteLine( " *  The value of String str2 is '{0}'.", str2 );
   Console::WriteLine( "    Is str1 equal to str2?: {0}", str1->Equals(
 str2 ) );
   Console::WriteLine();
   Console::WriteLine( " 3) String::Equals(String, String)" );
   Console::WriteLine( "    Is str1 equal to str2?: {0}", String::Equals(
 str1, str2 ) );
}

/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String::Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String::Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String::Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String::Equals(String, String)
    Is str1 equal to str2?: True
*/
// Sample for String.Equals(Object)
//            String.Equals(String)
//            String.Equals(String, String)
import System.*;
import System.Text.*;

class Sample
{
    public static void main(String[]
 args)
    {
        StringBuilder sb = new StringBuilder("abcd");
        String str1 = "abcd";
        String str2 = null;
        Object o2 = null;

        Console.WriteLine();
        Console.WriteLine(" *  The value of String str1 is '{0}'.", str1);
        Console.WriteLine(" *  The value of StringBuilder sb is '{0}'.",
 
            sb.ToString());

        Console.WriteLine();
        Console.WriteLine("1a) String.Equals(Object). Object is a " 
            + "StringBuilder, not a String.");
        Console.WriteLine("    Is str1 equal to sb?: {0}", 
            System.Convert.ToString(str1.Equals(sb)));

        Console.WriteLine();
        Console.WriteLine("1b) String.Equals(Object). Object is a String.");
        str2 = sb.ToString();
        o2 = str2;
        Console.WriteLine(" *  The value of Object o2 is '{0}'.", o2);
        Console.WriteLine("    Is str1 equal to o2?: {0}", 
            System.Convert.ToString(str1.Equals(o2)));

        Console.WriteLine();
        Console.WriteLine(" 2) String.Equals(String)");
        Console.WriteLine(" *  The value of String str2 is '{0}'.", str2);
        Console.WriteLine("    Is str1 equal to str2?: {0}", 
            System.Convert.ToString(str1.Equals(str2)));

        Console.WriteLine();
        Console.WriteLine(" 3) String.Equals(String, String)");
        Console.WriteLine("    Is str1 equal to str2?: {0}", 
            System.Convert.ToString(String.Equals(str1, str2)));
    } //main
} //Sample
/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String.Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String.Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String.Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String.Equals(String, String)
    Is str1 equal to str2?: True
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.Equals メソッド (String)

このインスタンスと、指定した別の String の値が同一かどうか判断します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

NullReferenceException

このインスタンスnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

Equals メソッドコード例次に示します

' Override the 'FormatDataValue' method.
Protected Overrides Function
 FormatDataValue(ByVal dataValue As Object)
 As String
   Dim myString As String
 = dataValue.ToString()
   ' Get the DataFormat.
   Dim myFormat As String
 = Me.DataFormatString
   Dim mySubString As String
 = myFormat.Substring(2, 3)
   ' Check for the currency format.
   If mySubString.Equals(":c}")
 Then
      Return "$" & myString
   Else
      Return myString
   End If
End Function
// Override the 'FormatDataValue' method.
protected override string FormatDataValue(object
 dataValue) 
{
   string myString = dataValue.ToString();
   // Get the DataFormat.
   string myFormat = this.DataFormatString;
   string mySubString = myFormat.Substring(2,3);
   // Check for the currency format.
   if (mySubString.Equals(":c}"))
   {
      return "$" + myString;
   }
   else
      return myString;
}
// Override the 'FormatDataValue' method.
virtual String^ FormatDataValue( Object^ dataValue ) override
{
   String^ myString = dataValue->ToString();
   
   // Get the DataFormat.
   String^ myFormat = this->DataFormatString;
   String^ mySubString = myFormat->Substring( 2, 3 );
   
   // Check for the currency format.
   if ( mySubString->Equals( ":c}" ) )
   {
      return String::Format( "${0}", myString );
   }
   else
            return myString;
}
// Override the 'FormatDataValue' method.
protected String FormatDataValue(Object dataValue)
{
    String myString = dataValue.ToString();

    // Get the DataFormat.
    String myFormat = this.get_DataFormatString();
    String mySubString = myFormat.Substring(2, 3);

    // Check for the currency format.
    if (mySubString.Equals(":c}")) {
        return "$" + myString;
    }
    else {
        return myString;
    }
} //FormatDataValue 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.Equals メソッド (String, StringComparison)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

この文字列と、指定した String オブジェクトの値が同一かどうか判断します比較使用するカルチャ、大文字と小文字区別、および、並べ替え規則パラメータ指定します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function Equals ( _
    value As String, _
    comparisonType As StringComparison _
) As Boolean
Dim instance As String
Dim value As String
Dim comparisonType As StringComparison
Dim returnValue As Boolean

returnValue = instance.Equals(value, comparisonType)
public bool Equals (
    string value,
    StringComparison comparisonType
)
public:
bool Equals (
    String^ value, 
    StringComparison comparisonType
)
public boolean Equals (
    String value, 
    StringComparison comparisonType
)
public function Equals (
    value : String, 
    comparisonType : StringComparison
) : boolean

パラメータ

value

String オブジェクト

comparisonType

System.StringComparison 値の 1 つ

戻り値
value パラメータの値がこの文字列と同じ場合trueそれ以外場合false

例外例外
例外種類条件

NullReferenceException

この文字列null 参照 (Visual Basic では Nothing) です。

ArgumentException

comparisonTypeStringComparison 値ではありません。

解説解説

comparisonType パラメータは、比較種類 (現在のカルチャを使用するかインバリアント カルチャを使用するか、比較対象値の大文字と小文字区別するか、並べ替え規則単語使用する序数使用するか) を指定します

使用例使用例

Equals メソッドを 3 とおりの方法使用しString オブジェクトと StringBuilder オブジェクトとが等しかどうか判断するコード例次に示します選択したカルチャ、大文字と小文字区別比較種類 (序数ベースにしたかどうか) が実行結果影響します

' This example demonstrates the 
' System.String.Equals(String, StringComparison) method.

Imports System
Imports System.Threading

Class Sample
    Public Shared Sub Main()
 
        Dim intro As String
 = "Compare three versions of the letter I using different "
 + "values of StringComparison."
        
        ' Define an array of strings where each element contains a version
 of the 
        ' letter I. (An array of strings is used so you can easily modify
 this 
        ' code example to test additional or different combinations
 of strings.)  
        Dim threeIs(2) As String
        ' LATIN SMALL LETTER I (U+0069)
        threeIs(0) = "i"
        ' LATIN SMALL LETTER DOTLESS I (U+0131)
        threeIs(1) = "ı"
        ' LATIN CAPITAL LETTER I (U+0049)
        threeIs(2) = "I"
        
        Dim unicodeNames As String()
 = { _
                             "LATIN SMALL LETTER I (U+0069)",
 _
                             "LATIN SMALL LETTER DOTLESS I (U+0131)",
 _
                             "LATIN CAPITAL LETTER I (U+0049)"
 }
        
        Dim scValues As StringComparison()
 = { _
                        StringComparison.CurrentCulture, _
                        StringComparison.CurrentCultureIgnoreCase, _
                        StringComparison.InvariantCulture, _
                        StringComparison.InvariantCultureIgnoreCase, _
                        StringComparison.Ordinal, _
                        StringComparison.OrdinalIgnoreCase }
        '
        Console.Clear()
        Console.WriteLine(intro)
        
        ' Display the current culture because the culture-specific comparisons
        ' can produce different results with different cultures.
        Console.WriteLine("The current culture is {0}."
 & vbCrLf, _
                           Thread.CurrentThread.CurrentCulture.Name)
        
        ' Determine whether three versions of the letter I are equal
 to each other. 
        Dim sc As StringComparison
        For Each sc In 
 scValues
            Console.WriteLine("StringComparison.{0}:",
 sc)
            
            ' LATIN SMALL LETTER I (U+0069) : LATIN SMALL LETTER DOTLESS
 I (U+0131)
            Test(0, 1, sc, threeIs, unicodeNames)
            
            ' LATIN SMALL LETTER I (U+0069) : LATIN CAPITAL LETTER I
 (U+0049)
            Test(0, 2, sc, threeIs, unicodeNames)
            
            ' LATIN SMALL LETTER DOTLESS I (U+0131) : LATIN CAPITAL
 LETTER I (U+0049)
            Test(1, 2, sc, threeIs, unicodeNames)
            
            Console.WriteLine()
        Next sc
    
    End Sub 'Main
    
    Protected Shared Sub
 Test(ByVal x As Integer,
 ByVal y As Integer, _
                              ByVal comparison As
 StringComparison, _
                              ByVal testI() As
 String, ByVal testNames() As
 String) 
        Dim resultFmt As String
 = "{0} is {1}equal to {2}"
        Dim result As String
 = "not "
        '
        If testI(x).Equals(testI(y), comparison) Then
            result = ""
        End If
        Console.WriteLine(resultFmt, testNames(x), result, testNames(y))
    
    End Sub 'Test
End Class 'Sample

'
'This code example produces the following results:
'
'Compare three versions of the letter I using different values of StringComparison.
'The current culture is en-US.
'
'StringComparison.CurrentCulture:
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS
 I (U+0131)
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER
 I (U+0049)
'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL
 LETTER I (U+0049)
'
'StringComparison.CurrentCultureIgnoreCase:
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS
 I (U+0131)
'LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL
 LETTER I (U+0049)
'
'StringComparison.InvariantCulture:
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS
 I (U+0131)
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER
 I (U+0049)
'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL
 LETTER I (U+0049)
'
'StringComparison.InvariantCultureIgnoreCase:
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS
 I (U+0131)
'LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL
 LETTER I (U+0049)
'
'StringComparison.Ordinal:
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS
 I (U+0131)
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER
 I (U+0049)
'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL
 LETTER I (U+0049)
'
'StringComparison.OrdinalIgnoreCase:
'LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS
 I (U+0131)
'LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
'LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL
 LETTER I (U+0049)
'
'
// This example demonstrates the 
// System.String.Equals(String, StringComparison) method.

using System;
using System.Threading;

class Sample 
{
    public static void Main()
 
    {
    string intro = "Compare three versions of the letter
 I using different " + 
                   "values of StringComparison.";

// Define an array of strings where each element contains a version
 of the 
// letter I. (An array of strings is used so you can easily modify this
 
// code example to test additional or different combinations of strings.)
  

    string[] threeIs = new string[3];
// LATIN SMALL LETTER I (U+0069)
    threeIs[0] = "\u0069";
// LATIN SMALL LETTER DOTLESS I (U+0131)
    threeIs[1] = "\u0131";
// LATIN CAPITAL LETTER I (U+0049)
    threeIs[2] = "\u0049";

    string[] unicodeNames = 
             {
             "LATIN SMALL LETTER I (U+0069)", 
             "LATIN SMALL LETTER DOTLESS I (U+0131)", 
             "LATIN CAPITAL LETTER I (U+0049)"
             };

    StringComparison[] scValues = {
        StringComparison.CurrentCulture,
        StringComparison.CurrentCultureIgnoreCase,
        StringComparison.InvariantCulture,
        StringComparison.InvariantCultureIgnoreCase,
        StringComparison.Ordinal,
        StringComparison.OrdinalIgnoreCase };

//
    Console.Clear();
    Console.WriteLine(intro);

// Display the current culture because the culture-specific comparisons
// can produce different results with different cultures.
    Console.WriteLine("The current culture is {0}.\n", 
                       Thread.CurrentThread.CurrentCulture.Name);

// Determine whether three versions of the letter I are equal to each
 other. 
    foreach (StringComparison sc in scValues)
        {
        Console.WriteLine("StringComparison.{0}:", sc);

// LATIN SMALL LETTER I (U+0069) : LATIN SMALL LETTER DOTLESS I (U+0131)
        Test(0, 1, sc, threeIs, unicodeNames);

// LATIN SMALL LETTER I (U+0069) : LATIN CAPITAL LETTER I (U+0049)
        Test(0, 2, sc, threeIs, unicodeNames);

// LATIN SMALL LETTER DOTLESS I (U+0131) : LATIN CAPITAL LETTER I (U+0049)
        Test(1, 2, sc, threeIs, unicodeNames);

        Console.WriteLine();
        }
    }

    protected static void
 Test(int x, int y, 
                               StringComparison comparison, 
                               string[] testI, string[]
 testNames)
    {
    string resultFmt = "{0} is {1}equal to {2}";
    string result = "not ";
//
    if (testI[x].Equals(testI[y], comparison)) 
        result = "";
    Console.WriteLine(resultFmt, testNames[x], result, testNames[y]);
    }
}

/*
This code example produces the following results:

Compare three versions of the letter I using different values
 of StringComparison.
The current culture is en-US.

StringComparison.CurrentCulture:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.CurrentCultureIgnoreCase:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.InvariantCulture:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.InvariantCultureIgnoreCase:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.Ordinal:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.OrdinalIgnoreCase:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

*/
// This example demonstrates the 
// System.String.Equals(String, StringComparison) method.

using namespace System;
using namespace System::Threading;

void Test(int testStringIndex, int
 comparisonStringIndex,
     StringComparison comparison, array<String^>^ testI, 
     array<String^>^ testNames)
{
    String^ resultFormat = "{0} is {1}equal to {2}";
    String^ resultString = "not ";

    if (testI[testStringIndex]->Equals(testI[comparisonStringIndex]
,
        comparison))
    {
        resultString = "";
    }
    Console::WriteLine(resultFormat, testNames[testStringIndex],
        resultString, testNames[comparisonStringIndex]);
}

int main()
{
    String^ introMessage =
        "Compare three versions of the letter I using different
 " +
        "values of StringComparison.";

    // Define an array of strings where each element contains a version
 of
    // the letter I. (An array of strings is used so you can easily
 modify
    // this code example to test additional or different combinations
 of
    // strings.)  
    array<String^>^ letterVariation = gcnew array<String^>(3);

    // LATIN SMALL LETTER I (U+0069)
    letterVariation[0] = "i";

    // LATIN SMALL LETTER DOTLESS I (U+0131)
    letterVariation[1] = L"\u0131";

    // LATIN CAPITAL LETTER I (U+0049)
    letterVariation[2] = "I";

    array<String^>^ unicodeNames = {
        "LATIN SMALL LETTER I (U+0069)",
        "LATIN SMALL LETTER DOTLESS I (U+0131)",
        "LATIN CAPITAL LETTER I (U+0049)"};

        array<StringComparison>^ comparisonValues = {
            StringComparison::CurrentCulture,
            StringComparison::CurrentCultureIgnoreCase,
            StringComparison::InvariantCulture,
            StringComparison::InvariantCultureIgnoreCase,
            StringComparison::Ordinal,
            StringComparison::OrdinalIgnoreCase};

        Console::Clear();
        Console::WriteLine(introMessage);

        // Display the current culture because the culture-specific
 comparisons
        // can produce different results with different cultures.
        Console::WriteLine("The current culture is {0}.\n",
            Thread::CurrentThread->CurrentCulture->Name);

        // Determine whether three versions of the letter I are equal
 to each
        // other. 
        for each (StringComparison stringCmp in
 comparisonValues)
        {
            Console::WriteLine("StringComparison.{0}:", stringCmp);

            // LATIN SMALL LETTER I (U+0069) : LATIN SMALL LETTER DOTLESS
 I
            // (U+0131)
            Test(0, 1, stringCmp, letterVariation, unicodeNames);

            // LATIN SMALL LETTER I (U+0069) : LATIN CAPITAL LETTER
 I (U+0049)
            Test(0, 2, stringCmp, letterVariation, unicodeNames);

            // LATIN SMALL LETTER DOTLESS I (U+0131) : LATIN CAPITAL
 LETTER I
            // (U+0049)
            Test(1, 2, stringCmp, letterVariation, unicodeNames);

            Console::WriteLine();
        }
}

/*
This code example produces the following results:

Compare three versions of the letter I using different values
 of StringComparison.
The current culture is en-US.

StringComparison.CurrentCulture:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.CurrentCultureIgnoreCase:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.InvariantCulture:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.InvariantCultureIgnoreCase:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.Ordinal:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is not equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

StringComparison.OrdinalIgnoreCase:
LATIN SMALL LETTER I (U+0069) is not equal to LATIN SMALL LETTER DOTLESS I (U+0131)
LATIN SMALL LETTER I (U+0069) is equal to LATIN CAPITAL LETTER I (U+0049)
LATIN SMALL LETTER DOTLESS I (U+0131) is not equal to LATIN CAPITAL LETTER I (U+0049)

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.Equals メソッド (Object)

String のこのインスタンスと、指定したオブジェクトの値が同一かどうか判断しますString オブジェクト指定する必要があります

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

NullReferenceException

このインスタンスnull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

Equals メソッドコード例次に示します

' Sample for String.Equals(Object)
'            String.Equals(String)
'            String.Equals(String, String)
Imports System
Imports System.Text

Class Sample
   Public Shared Sub Main()
      Dim sb As New StringBuilder("abcd")
      Dim str1 As [String] = "abcd"
      Dim str2 As [String] = Nothing
      Dim o2 As [Object] = Nothing
      
      Console.WriteLine()
      Console.WriteLine(" *  The value of String
 str1 is '{0}'.", str1)
      Console.WriteLine(" *  The value of StringBuilder sb
 is '{0}'.", sb.ToString())
      
      Console.WriteLine()
      Console.WriteLine("1a) String.Equals(Object). Object is
 a StringBuilder, not a String.")
      Console.WriteLine("    Is str1 equal to sb?: {0}",
 str1.Equals(sb))
      
      Console.WriteLine()
      Console.WriteLine("1b) String.Equals(Object). Object is
 a String.")
      str2 = sb.ToString()
      o2 = str2
      Console.WriteLine(" *  The value of Object
 o2 is '{0}'.", o2)
      Console.WriteLine("    Is str1 equal to o2?: {0}",
 str1.Equals(o2))
      
      Console.WriteLine()
      Console.WriteLine(" 2) String.Equals(String)")
      Console.WriteLine(" *  The value of String
 str2 is '{0}'.", str2)
      Console.WriteLine("    Is str1 equal to str2?: {0}",
 str1.Equals(str2))
      
      Console.WriteLine()
      Console.WriteLine(" 3) String.Equals(String, String)")
      Console.WriteLine("    Is str1 equal to str2?: {0}",
 [String].Equals(str1, str2))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
' *  The value of String str1 is 'abcd'.
' *  The value of StringBuilder sb is 'abcd'.
'
'1a) String.Equals(Object). Object is a StringBuilder, not a String.
'    Is str1 equal to sb?: False
'
'1b) String.Equals(Object). Object is a String.
' *  The value of Object o2 is 'abcd'.
'    Is str1 equal to o2?: True
'
' 2) String.Equals(String)
' *  The value of String str2 is 'abcd'.
'    Is str1 equal to str2?: True
'
' 3) String.Equals(String, String)
'    Is str1 equal to str2?: True
'
// Sample for String.Equals(Object)
//            String.Equals(String)
//            String.Equals(String, String)
using System;
using System.Text;

class Sample {
    public static void Main()
 {
    StringBuilder sb = new StringBuilder("abcd");
    String      str1 = "abcd";
    String      str2 = null;
    Object    o2   = null;

    Console.WriteLine();
    Console.WriteLine(" *  The value of String str1 is '{0}'.", str1);
    Console.WriteLine(" *  The value of StringBuilder sb is '{0}'.", sb.ToString());

    Console.WriteLine();
    Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder,
 not a String.");
    Console.WriteLine("    Is str1 equal to sb?: {0}", str1.Equals(sb));

    Console.WriteLine();
    Console.WriteLine("1b) String.Equals(Object). Object is a String.");
    str2 = sb.ToString();
    o2   = str2;
    Console.WriteLine(" *  The value of Object o2 is '{0}'.", o2);
    Console.WriteLine("    Is str1 equal to o2?: {0}", str1.Equals(o2));

    Console.WriteLine();
    Console.WriteLine(" 2) String.Equals(String)");
    Console.WriteLine(" *  The value of String str2 is '{0}'.", str2);
    Console.WriteLine("    Is str1 equal to str2?: {0}", str1.Equals(str2));

    Console.WriteLine();
    Console.WriteLine(" 3) String.Equals(String, String)");
    Console.WriteLine("    Is str1 equal to str2?: {0}", String.Equals(str1,
 str2));
    }
}
/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String.Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String.Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String.Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String.Equals(String, String)
    Is str1 equal to str2?: True
*/
// Sample for String::Equals(Object)
//            String::Equals(String)
//            String::Equals(String, String)
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder( "abcd" );
   String^ str1 = "abcd";
   String^ str2 = nullptr;
   Object^ o2 = nullptr;
   Console::WriteLine();
   Console::WriteLine( " *  The value of String str1 is '{0}'.", str1 );
   Console::WriteLine( " *  The value of StringBuilder sb is '{0}'.", sb
 );
   Console::WriteLine();
   Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder,
 not a String." );
   Console::WriteLine( "    Is str1 equal to sb?: {0}", str1->Equals(
 sb ) );
   Console::WriteLine();
   Console::WriteLine( "1b) String::Equals(Object). Object is a String."
 );
   str2 = sb->ToString();
   o2 = str2;
   Console::WriteLine( " *  The value of Object o2 is '{0}'.", o2 );
   Console::WriteLine( "    Is str1 equal to o2?: {0}", str1->Equals(
 o2 ) );
   Console::WriteLine();
   Console::WriteLine( " 2) String::Equals(String)" );
   Console::WriteLine( " *  The value of String str2 is '{0}'.", str2 );
   Console::WriteLine( "    Is str1 equal to str2?: {0}", str1->Equals(
 str2 ) );
   Console::WriteLine();
   Console::WriteLine( " 3) String::Equals(String, String)" );
   Console::WriteLine( "    Is str1 equal to str2?: {0}", String::Equals(
 str1, str2 ) );
}

/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String::Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String::Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String::Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String::Equals(String, String)
    Is str1 equal to str2?: True
*/
// Sample for String.Equals(Object)
//            String.Equals(String)
//            String.Equals(String, String)
import System.*;
import System.Text.*;

class Sample
{
    public static void main(String[]
 args)
    {
        StringBuilder sb = new StringBuilder("abcd");
        String str1 = "abcd";
        String str2 = null;
        Object o2 = null;

        Console.WriteLine();
        Console.WriteLine(" *  The value of String str1 is '{0}'.", str1);
        Console.WriteLine(" *  The value of StringBuilder sb is '{0}'.",
 
            sb.ToString());

        Console.WriteLine();
        Console.WriteLine("1a) String.Equals(Object). Object is a " 
            + "StringBuilder, not a String.");
        Console.WriteLine("    Is str1 equal to sb?: {0}", 
            System.Convert.ToString(str1.Equals(sb)));

        Console.WriteLine();
        Console.WriteLine("1b) String.Equals(Object). Object is a String.");
        str2 = sb.ToString();
        o2 = str2;
        Console.WriteLine(" *  The value of Object o2 is '{0}'.", o2);
        Console.WriteLine("    Is str1 equal to o2?: {0}", 
            System.Convert.ToString(str1.Equals(o2)));

        Console.WriteLine();
        Console.WriteLine(" 2) String.Equals(String)");
        Console.WriteLine(" *  The value of String str2 is '{0}'.", str2);
        Console.WriteLine("    Is str1 equal to str2?: {0}", 
            System.Convert.ToString(str1.Equals(str2)));

        Console.WriteLine();
        Console.WriteLine(" 3) String.Equals(String, String)");
        Console.WriteLine("    Is str1 equal to str2?: {0}", 
            System.Convert.ToString(String.Equals(str1, str2)));
    } //main
} //Sample
/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String.Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String.Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String.Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String.Equals(String, String)
    Is str1 equal to str2?: True
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

String.Equals メソッド

2 つString オブジェクトの値が同一かどうか判断します
オーバーロードの一覧オーバーロードの一覧

名前 説明
String.Equals (Object) String のこのインスタンスと、指定したオブジェクトの値が同一かどうか判断しますString オブジェクト指定する必要があります

.NET Compact Framework によってサポートされています。

String.Equals (String) このインスタンスと、指定した別の String の値が同一かどうか判断します

.NET Compact Framework によってサポートされています。

String.Equals (Object, Object) 指定した Object インスタンス等しかどうか判断します
String.Equals (String, String) 指定した 2 つString オブジェクトの値が同一かどうか判断します

.NET Compact Framework によってサポートされています。

String.Equals (String, StringComparison) この文字列と、指定した String オブジェクトの値が同一かどうか判断します比較使用するカルチャ、大文字と小文字区別、および、並べ替え規則パラメータ指定します

.NET Compact Framework によってサポートされています。

String.Equals (String, String, StringComparison) 指定した 2 つString オブジェクトの値が同一かどうか判断します比較使用するカルチャ、大文字と小文字区別、および、並べ替え規則パラメータ指定します

.NET Compact Framework によってサポートされています。

参照参照

String.Equals メソッド (String, String, StringComparison)

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定した 2 つString オブジェクトの値が同一かどうか判断します比較使用するカルチャ、大文字と小文字区別、および、並べ替え規則パラメータ指定します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Shared Function Equals
 ( _
    a As String, _
    b As String, _
    comparisonType As StringComparison _
) As Boolean
Dim a As String
Dim b As String
Dim comparisonType As StringComparison
Dim returnValue As Boolean

returnValue = String.Equals(a, b, comparisonType)
public static bool Equals
 (
    string a,
    string b,
    StringComparison comparisonType
)
public:
static bool Equals (
    String^ a, 
    String^ b, 
    StringComparison comparisonType
)
public static boolean Equals (
    String a, 
    String b, 
    StringComparison comparisonType
)
public static function Equals
 (
    a : String, 
    b : String, 
    comparisonType : StringComparison
) : boolean

パラメータ

a

String オブジェクトまたは null 参照 (Visual Basic では Nothing)。

b

String オブジェクトまたは null 参照 (Visual Basic では Nothing)。

comparisonType

System.StringComparison 値の 1 つ

戻り値
a パラメータの値が b パラメータの値に等し場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentException

comparisonTypeStringComparison 値ではありません。

解説解説

comparisonType パラメータは、比較種類 (現在のカルチャを使用するかインバリアント カルチャを使用するか、比較対象値の大文字と小文字区別するか、並べ替え規則単語使用する序数使用するか) を指定します

使用例使用例

Equals メソッドを 3 とおりの方法使用しString オブジェクトと StringBuilder オブジェクトとが等しかどうか判断するコード例次に示します

' Sample for String.Equals(Object)
'            String.Equals(String)
'            String.Equals(String, String)
Imports System
Imports System.Text

Class Sample
   Public Shared Sub Main()
      Dim sb As New StringBuilder("abcd")
      Dim str1 As [String] = "abcd"
      Dim str2 As [String] = Nothing
      Dim o2 As [Object] = Nothing
      
      Console.WriteLine()
      Console.WriteLine(" *  The value of String
 str1 is '{0}'.", str1)
      Console.WriteLine(" *  The value of StringBuilder sb
 is '{0}'.", sb.ToString())
      
      Console.WriteLine()
      Console.WriteLine("1a) String.Equals(Object). Object is
 a StringBuilder, not a String.")
      Console.WriteLine("    Is str1 equal to sb?: {0}",
 str1.Equals(sb))
      
      Console.WriteLine()
      Console.WriteLine("1b) String.Equals(Object). Object is
 a String.")
      str2 = sb.ToString()
      o2 = str2
      Console.WriteLine(" *  The value of Object
 o2 is '{0}'.", o2)
      Console.WriteLine("    Is str1 equal to o2?: {0}",
 str1.Equals(o2))
      
      Console.WriteLine()
      Console.WriteLine(" 2) String.Equals(String)")
      Console.WriteLine(" *  The value of String
 str2 is '{0}'.", str2)
      Console.WriteLine("    Is str1 equal to str2?: {0}",
 str1.Equals(str2))
      
      Console.WriteLine()
      Console.WriteLine(" 3) String.Equals(String, String)")
      Console.WriteLine("    Is str1 equal to str2?: {0}",
 [String].Equals(str1, str2))
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
' *  The value of String str1 is 'abcd'.
' *  The value of StringBuilder sb is 'abcd'.
'
'1a) String.Equals(Object). Object is a StringBuilder, not a String.
'    Is str1 equal to sb?: False
'
'1b) String.Equals(Object). Object is a String.
' *  The value of Object o2 is 'abcd'.
'    Is str1 equal to o2?: True
'
' 2) String.Equals(String)
' *  The value of String str2 is 'abcd'.
'    Is str1 equal to str2?: True
'
' 3) String.Equals(String, String)
'    Is str1 equal to str2?: True
'
// Sample for String.Equals(Object)
//            String.Equals(String)
//            String.Equals(String, String)
using System;
using System.Text;

class Sample {
    public static void Main()
 {
    StringBuilder sb = new StringBuilder("abcd");
    String      str1 = "abcd";
    String      str2 = null;
    Object    o2   = null;

    Console.WriteLine();
    Console.WriteLine(" *  The value of String str1 is '{0}'.", str1);
    Console.WriteLine(" *  The value of StringBuilder sb is '{0}'.", sb.ToString());

    Console.WriteLine();
    Console.WriteLine("1a) String.Equals(Object). Object is a StringBuilder,
 not a String.");
    Console.WriteLine("    Is str1 equal to sb?: {0}", str1.Equals(sb));

    Console.WriteLine();
    Console.WriteLine("1b) String.Equals(Object). Object is a String.");
    str2 = sb.ToString();
    o2   = str2;
    Console.WriteLine(" *  The value of Object o2 is '{0}'.", o2);
    Console.WriteLine("    Is str1 equal to o2?: {0}", str1.Equals(o2));

    Console.WriteLine();
    Console.WriteLine(" 2) String.Equals(String)");
    Console.WriteLine(" *  The value of String str2 is '{0}'.", str2);
    Console.WriteLine("    Is str1 equal to str2?: {0}", str1.Equals(str2));

    Console.WriteLine();
    Console.WriteLine(" 3) String.Equals(String, String)");
    Console.WriteLine("    Is str1 equal to str2?: {0}", String.Equals(str1,
 str2));
    }
}
/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String.Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String.Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String.Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String.Equals(String, String)
    Is str1 equal to str2?: True
*/
// Sample for String::Equals(Object)
//            String::Equals(String)
//            String::Equals(String, String)
using namespace System;
using namespace System::Text;
int main()
{
   StringBuilder^ sb = gcnew StringBuilder( "abcd" );
   String^ str1 = "abcd";
   String^ str2 = nullptr;
   Object^ o2 = nullptr;
   Console::WriteLine();
   Console::WriteLine( " *  The value of String str1 is '{0}'.", str1 );
   Console::WriteLine( " *  The value of StringBuilder sb is '{0}'.", sb
 );
   Console::WriteLine();
   Console::WriteLine( "1a) String::Equals(Object). Object is a StringBuilder,
 not a String." );
   Console::WriteLine( "    Is str1 equal to sb?: {0}", str1->Equals(
 sb ) );
   Console::WriteLine();
   Console::WriteLine( "1b) String::Equals(Object). Object is a String."
 );
   str2 = sb->ToString();
   o2 = str2;
   Console::WriteLine( " *  The value of Object o2 is '{0}'.", o2 );
   Console::WriteLine( "    Is str1 equal to o2?: {0}", str1->Equals(
 o2 ) );
   Console::WriteLine();
   Console::WriteLine( " 2) String::Equals(String)" );
   Console::WriteLine( " *  The value of String str2 is '{0}'.", str2 );
   Console::WriteLine( "    Is str1 equal to str2?: {0}", str1->Equals(
 str2 ) );
   Console::WriteLine();
   Console::WriteLine( " 3) String::Equals(String, String)" );
   Console::WriteLine( "    Is str1 equal to str2?: {0}", String::Equals(
 str1, str2 ) );
}

/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String::Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String::Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String::Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String::Equals(String, String)
    Is str1 equal to str2?: True
*/
// Sample for String.Equals(Object)
//            String.Equals(String)
//            String.Equals(String, String)
import System.*;
import System.Text.*;

class Sample
{
    public static void main(String[]
 args)
    {
        StringBuilder sb = new StringBuilder("abcd");
        String str1 = "abcd";
        String str2 = null;
        Object o2 = null;

        Console.WriteLine();
        Console.WriteLine(" *  The value of String str1 is '{0}'.", str1);
        Console.WriteLine(" *  The value of StringBuilder sb is '{0}'.",
 
            sb.ToString());

        Console.WriteLine();
        Console.WriteLine("1a) String.Equals(Object). Object is a " 
            + "StringBuilder, not a String.");
        Console.WriteLine("    Is str1 equal to sb?: {0}", 
            System.Convert.ToString(str1.Equals(sb)));

        Console.WriteLine();
        Console.WriteLine("1b) String.Equals(Object). Object is a String.");
        str2 = sb.ToString();
        o2 = str2;
        Console.WriteLine(" *  The value of Object o2 is '{0}'.", o2);
        Console.WriteLine("    Is str1 equal to o2?: {0}", 
            System.Convert.ToString(str1.Equals(o2)));

        Console.WriteLine();
        Console.WriteLine(" 2) String.Equals(String)");
        Console.WriteLine(" *  The value of String str2 is '{0}'.", str2);
        Console.WriteLine("    Is str1 equal to str2?: {0}", 
            System.Convert.ToString(str1.Equals(str2)));

        Console.WriteLine();
        Console.WriteLine(" 3) String.Equals(String, String)");
        Console.WriteLine("    Is str1 equal to str2?: {0}", 
            System.Convert.ToString(String.Equals(str1, str2)));
    } //main
} //Sample
/*
This example produces the following results:

 *  The value of String str1 is 'abcd'.
 *  The value of StringBuilder sb is 'abcd'.

1a) String.Equals(Object). Object is a StringBuilder, not a String.
    Is str1 equal to sb?: False

1b) String.Equals(Object). Object is a String.
 *  The value of Object o2 is 'abcd'.
    Is str1 equal to o2?: True

 2) String.Equals(String)
 *  The value of String str2 is 'abcd'.
    Is str1 equal to str2?: True

 3) String.Equals(String, String)
    Is str1 equal to str2?: True
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「String.Equals メソッド」の関連用語

String.Equals メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



String.Equals メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS