共用方式為


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

傳回

如果 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 實例對應至相同的字碼頁,且其 EncoderFallbackDecoderFallback 物件相等,則會視為相等。 特別是,衍生字碼頁全都有 0 的字碼頁,而且其後援通常會 null 在 Visual Basic .NET) 中 (Nothing 。 因此,它們全都視為彼此相等。 其中一個結果是,當 用來填入雜湊表時 Equals ,所有衍生的編碼都會比較相等,並落在相同的雜湊表位置。

適用於

另請參閱