UnicodeEncoding::Equals Method (Object^)

 

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

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

public:
virtual bool Equals(
	Object^ value
) override

Parameters

value
Type: System::Object^

The object to compare with the current object.

Return Value

Type: System::Boolean

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

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

  • Both objects use the same byte order (little-endian or big-endian).

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

  • Both objects use the same encoder fallback.

  • Both objects use the same decoder fallback.

The following 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.

using namespace System;
using namespace System::Text;
void DescribeEquivalence( Boolean isEquivalent )
{
   Console::WriteLine( " {0} equivalent encoding.", (isEquivalent ? (String^)"An" : "Not an") );
}

int main()
{

   // Create a UnicodeEncoding without parameters.
   UnicodeEncoding^ unicode = gcnew UnicodeEncoding;

   // Create a UnicodeEncoding to support little-endian Byte ordering
   // and include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeLittleEndianBOM = gcnew UnicodeEncoding( false,true );

   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeLittleEndianBOM ) );

   // Create a UnicodeEncoding to support little-endian Byte ordering
   // and not include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeLittleEndianNoBOM = gcnew UnicodeEncoding( false,false );

   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeLittleEndianNoBOM ) );

   // Create a UnicodeEncoding to support big-endian Byte ordering
   // and include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeBigEndianBOM = gcnew UnicodeEncoding( true,true );

   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeBigEndianBOM ) );

   // Create a UnicodeEncoding to support big-endian Byte ordering
   // and not include the Unicode Byte order mark.
   UnicodeEncoding^ unicodeBigEndianNoBOM = gcnew UnicodeEncoding( true,false );

   // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
   DescribeEquivalence( unicode->Equals( unicodeBigEndianNoBOM ) );
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: