UTF8Encoding.Equals Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Determines whether the specified Object is equal to the current UTF8Encoding object.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Object
The Object to compare with the current instance.
Return Value
Type: System.Booleantrue 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.
Imports System.Text Class Example Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 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(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)) End Sub 'Main 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 'DescribeEquivalence End Class 'UTF8EncodingExample