Export (0) Print
Expand All

UnicodeEncoding Constructor (Boolean, Boolean)

Initializes a new instance of the UnicodeEncoding class. Parameters specify whether to use the big endian byte order and whether to provide a Unicode byte order mark.

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

public:
UnicodeEncoding(
	bool bigEndian, 
	bool byteOrderMark
)

Parameters

bigEndian
Type: System::Boolean

true to use the big endian byte order (most significant byte first), or false to use the little endian byte order (least significant byte first).

byteOrderMark
Type: System::Boolean

true to specify that a Unicode byte order mark is provided; otherwise, false.

This constructor creates an instance that does not throw an exception when an invalid encoding is detected.

NoteNote

For security reasons, your applications are recommended to enable error detection by using the constructor that accepts a throwOnInvalidBytes parameter and setting that parameter to true.

The following code example demonstrates how to create a new UnicodeEncoding instance specifying whether to support little endian or big endian byte ordering and the Unicode byte order mark.

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 ) );
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft