UnicodeEncoding.Equals Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Overrides Function Equals ( _
    value As Object _
) As Boolean
public override bool Equals(
    Object value
)

Parameters

Return Value

Type: System.Boolean
true if value is an instance of UnicodeEncoding and is equal to the current object; otherwise, false.

Remarks

Two UnicodeEncoding 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.

Examples

The following code example demonstrates how to use the Equals method to test whether the current UnicodeEncoding object is equal to a different UnicodeEncoding object. Five UnicodeEncoding objects are created and compared, and the results of the comparisons are displayed.

Imports System.Text

Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Create a UnicodeEncoding without parameters.
      Dim unicodeDefault As New UnicodeEncoding()

      ' Create a UnicodeEncoding to support little-endian byte ordering
      ' and include the Unicode byte order mark.        
      Dim unicodeLittleEndianBOM As New UnicodeEncoding(False, True)
      ' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicodeDefault.Equals(unicodeLittleEndianBOM))

      ' Create a UnicodeEncoding to support little-endian byte ordering
      ' and not include the Unicode byte order mark.
      Dim unicodeLittleEndianNoBOM As New UnicodeEncoding(False, False)
      ' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicodeDefault.Equals(unicodeLittleEndianNoBOM))

      ' Create a UnicodeEncoding to support big-endian byte ordering
      ' and include the Unicode byte order mark.
      Dim unicodeBigEndianBOM As New UnicodeEncoding(True, True)
      ' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicodeDefault.Equals(unicodeBigEndianBOM))

      ' Create a UnicodeEncoding to support big-endian byte ordering
      ' and not include the Unicode byte order mark.
      Dim unicodeBigEndianNoBOM As New UnicodeEncoding(True, False)
      ' Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicodeDefault.Equals(unicodeBigEndianNoBOM))
   End Sub


   Public Shared Sub DescribeEquivalence(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal isEquivalent As Boolean)
      Dim phrase As String
      If isEquivalent Then
         phrase = "An"
      Else
         phrase = "Not an"
      End If
      outputBlock.Text += String.Format("{0} equivalent encoding.", phrase) & vbCrLf
   End Sub
End Class
using System;
using System.Text;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      // Create a UnicodeEncoding without parameters.
      UnicodeEncoding unicode = new UnicodeEncoding();

      // Create a UnicodeEncoding to support little-endian byte ordering
      // and include the Unicode byte order mark.
      UnicodeEncoding unicodeLittleEndianBOM =
          new UnicodeEncoding(false, true);
      // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicode.Equals(unicodeLittleEndianBOM));

      // Create a UnicodeEncoding to support little-endian byte ordering
      // and not include the Unicode byte order mark.
      UnicodeEncoding unicodeLittleEndianNoBOM =
          new UnicodeEncoding(false, false);
      // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicode.Equals(unicodeLittleEndianNoBOM));

      // Create a UnicodeEncoding to support big-endian byte ordering
      // and include the Unicode byte order mark.
      UnicodeEncoding unicodeBigEndianBOM =
          new UnicodeEncoding(true, true);
      // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicode.Equals(unicodeBigEndianBOM));

      // Create a UnicodeEncoding to support big-endian byte ordering
      // and not include the Unicode byte order mark.
      UnicodeEncoding unicodeBigEndianNoBOM =
          new UnicodeEncoding(true, false);
      // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
      DescribeEquivalence(outputBlock, unicode.Equals(unicodeBigEndianNoBOM));
   }

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

Version Information

Silverlight

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

Platforms

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