Encoding.Equals(Object) 方法

定义

确定指定的 Object 是否等同于当前实例。

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

与当前实例进行比较的 Object

返回

Boolean

如果 valueEncoding 的一个实例并且等于当前实例,则为 true;否则,为 false

示例

下面的示例获取相同编码的两个实例(一个按代码页,另一个按名称),并检查它们是否相等。

using namespace System;
using namespace System::Text;
int main()
{
   
   // Get a UTF-32 encoding by codepage.
   Encoding^ e1 = Encoding::GetEncoding( 12000 );
   
   // Get a UTF-32 encoding by name.
   Encoding^ e2 = Encoding::GetEncoding( "utf-32" );
   
   // Check their equality.
   Console::WriteLine( "e1 equals e2? {0}", e1->Equals( e2 ) );
}

/* 
This code produces the following output.

e1 equals e2? True

*/
using System;
using System.Text;

public class SamplesEncoding  {

   public static void Main()  {

      // Get a UTF-32 encoding by codepage.
      Encoding e1 = Encoding.GetEncoding( 12000 );

      // Get a UTF-32 encoding by name.
      Encoding e2 = Encoding.GetEncoding( "utf-32" );

      // Check their equality.
      Console.WriteLine( "e1 equals e2? {0}", e1.Equals( e2 ) );
   }
}


/* 
This code produces the following output.

e1 equals e2? True

*/
Imports System.Text

Public Class SamplesEncoding   

   Public Shared Sub Main()

      ' Get a UTF-32 encoding by codepage.
      Dim e1 As Encoding = Encoding.GetEncoding(12000)

      ' Get a UTF-32 encoding by name.
      Dim e2 As Encoding = Encoding.GetEncoding("utf-32")

      ' Check their equality.
      Console.WriteLine("e1 equals e2? {0}", e1.Equals(e2))

   End Sub

End Class


'This code produces the following output.
'
'e1 equals e2? True

注解

如果两个实例 Encoding 对应于同一个代码页并且它们 EncoderFallback 和对象相等,则这两个实例被视为相等 DecoderFallback 。 具体而言,派生代码页的代码页都为0,并且它们的回退通常为 nullNothing 在 Visual Basic .net 中)。 因此,它们被视为彼此相等。 一种结果是,当 Equals 使用来填充哈希表时,所有派生的编码都相等并属于同一哈希表槽。

适用于

另请参阅