This documentation is archived and is not being maintained.

UTF8Encoding.Equals Method (Object)

Determines whether the specified Object is equal to the current instance.

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

public override bool Equals (
	Object value
)
public boolean Equals (
	Object value
)
public override function Equals (
	value : Object
) : boolean

Parameters

value

The Object to compare with the current instance.

Return Value

true if value is an instance of UTF8Encoding and is equal to the current instance; otherwise, false.

Two instances of UTF8Encoding are considered equal if all of the following conditions are true:

  • Both instances use the same byte order.

  • Both instances provide the byte order mark, or both do not.

  • Both instances throw an exception when encountering invalid encoding, or both do not.

The following example demonstrates how to use the Equals method to test whether this instance of UTF8Encoding is equal to a different instance of UTF8Encoding. Four instances of UTF8Encoding are created and compared and the results of the comparisons are displayed.

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")
        );
    }
}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[] args)
    {
        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));
    } //main

    public static void DescribeEquivalence(boolean isEquivalent)
    {
        Console.WriteLine("{0} equivalent encoding.", 
            (isEquivalent) ? "An" : "Not an");
    } //DescribeEquivalence
} //UTF8EncodingExample

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: