UTF8Encoding.Equals Method

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


Type: System.Object
The Object to compare with the current instance.

Return Value

Type: System.Boolean
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 Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      UTF8Encoding utf8 = new UTF8Encoding();
      UTF8Encoding utf8true = new UTF8Encoding(true);
      UTF8Encoding utf8truetrue = new UTF8Encoding(true, true);
      UTF8Encoding utf8falsetrue = new UTF8Encoding(false, true);

      DescribeEquivalence(outputBlock, utf8.Equals(utf8));
      DescribeEquivalence(outputBlock, utf8.Equals(utf8true));
      DescribeEquivalence(outputBlock, utf8.Equals(utf8truetrue));
      DescribeEquivalence(outputBlock, utf8.Equals(utf8falsetrue));

      DescribeEquivalence(outputBlock, utf8true.Equals(utf8));
      DescribeEquivalence(outputBlock, utf8true.Equals(utf8true));
      DescribeEquivalence(outputBlock, utf8true.Equals(utf8truetrue));
      DescribeEquivalence(outputBlock, utf8true.Equals(utf8falsetrue));

      DescribeEquivalence(outputBlock, utf8truetrue.Equals(utf8));
      DescribeEquivalence(outputBlock, utf8truetrue.Equals(utf8true));
      DescribeEquivalence(outputBlock, utf8truetrue.Equals(utf8truetrue));
      DescribeEquivalence(outputBlock, utf8truetrue.Equals(utf8falsetrue));

      DescribeEquivalence(outputBlock, utf8falsetrue.Equals(utf8));
      DescribeEquivalence(outputBlock, utf8falsetrue.Equals(utf8true));
      DescribeEquivalence(outputBlock, utf8falsetrue.Equals(utf8truetrue));
      DescribeEquivalence(outputBlock, utf8falsetrue.Equals(utf8falsetrue));

   public static void DescribeEquivalence(System.Windows.Controls.TextBlock outputBlock, Boolean isEquivalent)
      outputBlock.Text += String.Format(
          "{0} equivalent encoding.", (isEquivalent ? "An" : "Not an")
      ) + "\n";


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions