共用方式為


UTF8Encoding.Equals(Object) 方法

定義

判斷指定的物件是否等於目前的 UTF8Encoding 物件。

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

要與目前執行個體比較的物件。

傳回

如果 valueUTF8Encoding 的執行個體,並且等於目前的物件,則為 true;否則為 false

範例

下列範例會 Equals 使用 方法來測試目前的 UTF8Encoding 物件是否等於不同的 UTF8Encoding 物件。 系統會建立並比較四 UTF8Encoding 個物件,並顯示比較的結果。

using namespace System;
using namespace System::Text;
void DescribeEquivalence( Boolean isEquivalent )
{
   Console::WriteLine( "{0} equivalent encoding.", (isEquivalent ? (String^)"An" : "Not an") );
}

int main()
{
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   UTF8Encoding^ utf8true = gcnew UTF8Encoding( true );
   UTF8Encoding^ utf8truetrue = gcnew UTF8Encoding( true,true );
   UTF8Encoding^ utf8falsetrue = gcnew UTF8Encoding( false,true );
   DescribeEquivalence( utf8->Equals( utf8 ) );
   DescribeEquivalence( utf8->Equals( utf8true ) );
   DescribeEquivalence( utf8->Equals( utf8truetrue ) );
   DescribeEquivalence( utf8->Equals( utf8falsetrue ) );
   DescribeEquivalence( utf8true->Equals( utf8 ) );
   DescribeEquivalence( utf8true->Equals( utf8true ) );
   DescribeEquivalence( utf8true->Equals( utf8truetrue ) );
   DescribeEquivalence( utf8true->Equals( utf8falsetrue ) );
   DescribeEquivalence( utf8truetrue->Equals( utf8 ) );
   DescribeEquivalence( utf8truetrue->Equals( utf8true ) );
   DescribeEquivalence( utf8truetrue->Equals( utf8truetrue ) );
   DescribeEquivalence( utf8truetrue->Equals( utf8falsetrue ) );
   DescribeEquivalence( utf8falsetrue->Equals( utf8 ) );
   DescribeEquivalence( utf8falsetrue->Equals( utf8true ) );
   DescribeEquivalence( utf8falsetrue->Equals( utf8truetrue ) );
   DescribeEquivalence( utf8falsetrue->Equals( utf8falsetrue ) );
}
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main() {
        UTF8Encoding utf8 = new UTF8Encoding();
        UTF8Encoding utf8true = new UTF8Encoding(true);
        UTF8Encoding utf8truetrue = new UTF8Encoding(true, true);
        UTF8Encoding utf8falsetrue = new UTF8Encoding(false, true);
        
        DescribeEquivalence(utf8.Equals(utf8));
        DescribeEquivalence(utf8.Equals(utf8true));
        DescribeEquivalence(utf8.Equals(utf8truetrue));
        DescribeEquivalence(utf8.Equals(utf8falsetrue));
        
        DescribeEquivalence(utf8true.Equals(utf8));
        DescribeEquivalence(utf8true.Equals(utf8true));
        DescribeEquivalence(utf8true.Equals(utf8truetrue));
        DescribeEquivalence(utf8true.Equals(utf8falsetrue));
        
        DescribeEquivalence(utf8truetrue.Equals(utf8));
        DescribeEquivalence(utf8truetrue.Equals(utf8true));
        DescribeEquivalence(utf8truetrue.Equals(utf8truetrue));
        DescribeEquivalence(utf8truetrue.Equals(utf8falsetrue));
        
        DescribeEquivalence(utf8falsetrue.Equals(utf8));
        DescribeEquivalence(utf8falsetrue.Equals(utf8true));
        DescribeEquivalence(utf8falsetrue.Equals(utf8truetrue));
        DescribeEquivalence(utf8falsetrue.Equals(utf8falsetrue));
    }

    public static void DescribeEquivalence(Boolean isEquivalent) {
        Console.WriteLine(
            "{0} equivalent encoding.", (isEquivalent ? "An" : "Not an")
        );
    }
}
Imports System.Text

Class UTF8EncodingExample
    
    Public Shared Sub Main()
        Dim utf8 As New UTF8Encoding()
        Dim utf8true As New UTF8Encoding(True)
        Dim utf8truetrue As New UTF8Encoding(True, True)
        Dim utf8falsetrue As New UTF8Encoding(False, True)
        
        DescribeEquivalence(utf8.Equals(utf8))
        DescribeEquivalence(utf8.Equals(utf8true))
        DescribeEquivalence(utf8.Equals(utf8truetrue))
        DescribeEquivalence(utf8.Equals(utf8falsetrue))
        
        DescribeEquivalence(utf8true.Equals(utf8))
        DescribeEquivalence(utf8true.Equals(utf8true))
        DescribeEquivalence(utf8true.Equals(utf8truetrue))
        DescribeEquivalence(utf8true.Equals(utf8falsetrue))
        
        DescribeEquivalence(utf8truetrue.Equals(utf8))
        DescribeEquivalence(utf8truetrue.Equals(utf8true))
        DescribeEquivalence(utf8truetrue.Equals(utf8truetrue))
        DescribeEquivalence(utf8truetrue.Equals(utf8falsetrue))
        
        DescribeEquivalence(utf8falsetrue.Equals(utf8))
        DescribeEquivalence(utf8falsetrue.Equals(utf8true))
        DescribeEquivalence(utf8falsetrue.Equals(utf8truetrue))
        DescribeEquivalence(utf8falsetrue.Equals(utf8falsetrue))
    End Sub
    
    
    Public Shared Sub DescribeEquivalence(isEquivalent As Boolean)
        Dim phrase as String
        If isEquivalent Then
            phrase = "An"
        Else
            phrase = "Not an"
        End If
        Console.WriteLine("{0} equivalent encoding.", phrase)
    End Sub
End Class

備註

如果下列所有條件成立,則會將兩 UTF8Encoding 個物件視為相等:

  • 這兩個物件都提供位元組順序標記,或兩者都未提供。

  • 這兩個物件都使用相同的編碼器後援。

  • 這兩個物件都使用相同的解碼器後援。

適用於

另請參閱