Encoding.Equals(Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷指定的 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
參數
傳回
true 若 value 是 的 Encoding 一個實例,且等於當前實例;否則, false。
範例
以下範例會取得兩個相同編碼實例(一個依編碼頁,另一個依名稱),並檢查其相等性。
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,且其備援通常為 null(在 Visual Basic .NET 中為 Nothing)。 因此,他們都被視為彼此平等。 其中一個結果是,當用來填充雜湊表時 Equals ,所有導出編碼的比較結果相等,並落入同一個雜湊表欄位。