RegionInfo.Equals(Object) 方法

定义

确定指定的对象与当前 RegionInfo 是否为同一实例。

public:
 override bool Equals(System::Object ^ value);
public override bool Equals (object value);
public override bool Equals (object? value);
override this.Equals : obj -> bool
Public Overrides Function Equals (value As Object) As Boolean

参数

value
Object

将与当前 RegionInfo 进行比较的对象。

返回

如果 value 参数是 RegionInfo 对象并且其 Name 属性与当前 Name 对象的 RegionInfo 属性相同,则为 true;否则,为 false

示例

下面的代码示例比较了以不同方式创建的 的 RegionInfo 两个 实例。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates a RegionInfo using the ISO 3166 two-letter code.
   RegionInfo^ myRI1 = gcnew RegionInfo( "US" );
   
   // Creates a RegionInfo using a CultureInfo.LCID.
   RegionInfo^ myRI2 = gcnew RegionInfo( (gcnew CultureInfo( "en-US",false ))->LCID );
   
   // Compares the two instances.
   if ( myRI1->Equals( myRI2 ) )
      Console::WriteLine( "The two RegionInfo instances are equal." );
   else
      Console::WriteLine( "The two RegionInfo instances are NOT equal." );
}

/*
This code produces the following output.

The two RegionInfo instances are equal.

*/
using System;
using System.Globalization;

public class SamplesRegionInfo  {

   public static void Main()  {

      // Creates a RegionInfo using the ISO 3166 two-letter code.
      RegionInfo myRI1 = new RegionInfo( "US" );

      // Creates a RegionInfo using a CultureInfo.LCID.
      RegionInfo myRI2 = new RegionInfo( new CultureInfo("en-US",false).LCID );

      // Compares the two instances.
      if ( myRI1.Equals( myRI2 ) )
         Console.WriteLine( "The two RegionInfo instances are equal." );
      else
         Console.WriteLine( "The two RegionInfo instances are NOT equal." );
   }
}

/*
This code produces the following output.

The two RegionInfo instances are equal.

*/
Imports System.Globalization


Public Class SamplesRegionInfo   

   Public Shared Sub Main()

      ' Creates a RegionInfo using the ISO 3166 two-letter code.
      Dim myRI1 As New RegionInfo("US")

      ' Creates a RegionInfo using a CultureInfo.LCID.
      Dim myRI2 As New RegionInfo(New CultureInfo("en-US", False).LCID)

      ' Compares the two instances.
      If myRI1.Equals(myRI2) Then
         Console.WriteLine("The two RegionInfo instances are equal.")
      Else
         Console.WriteLine("The two RegionInfo instances are NOT equal.")
      End If 

   End Sub

End Class


'This code produces the following output.
'
'The two RegionInfo instances are equal.

注解

此方法重写 Object.Equals

适用于

另请参阅