UTF8Encoding.Equals Method (Object)

Determines whether the specified Object is equal to the current UTF8Encoding object.

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
Not applicable.

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 object; otherwise, false.

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

  • Both objects use the same byte order.

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

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

The following example demonstrates how to use the Equals method to test whether the current UTF8Encoding object is equal to a different UTF8Encoding object. Four UTF8Encoding objects 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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show: