Sdílet prostřednictvím


UTF8Encoding.Equals(Object) Metoda

Definice

Určuje, zda je zadaný objekt roven aktuálnímu UTF8Encoding objektu.

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

Parametry

value
Object

Objekt k porovnání s aktuální instancí.

Návraty

true pokud value je instancí objektu UTF8Encoding a je rovno aktuálnímu objektu, falsejinak hodnota .

Příklady

Následující příklad používá metodu Equals k testování, zda je aktuální UTF8Encoding objekt roven jinému UTF8Encoding objektu. Vytvoří se a UTF8Encoding porovná čtyři objekty a zobrazí se výsledky porovnání.

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

Poznámky

Dva UTF8Encoding objekty jsou považovány za stejné, pokud jsou splněny všechny následující podmínky:

  • Oba objekty poskytují značku pořadí bajtů, nebo je nemají.

  • Oba objekty používají stejný záložní kodér.

  • Oba objekty používají stejný záložní dekodér.

Platí pro

Viz také