UTF32Encoding Constructor (Boolean, Boolean)

 

Initializes a new instance of the UTF32Encoding class. Parameters specify whether to use the big endian byte order and whether the GetPreamble method returns a Unicode Unicode byte order mark.

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

public:
UTF32Encoding(
	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.

System_CAPS_noteNote

For security reasons, you should enable error detection by calling the UTF32Encoding(Boolean, Boolean, Boolean) constructor and setting its throwOnInvalidCharacters argument to true.

The following example retrieves and displays the byte order mark for different UTF32Encoding instances.

using namespace System;
using namespace System::Text;

void PrintHexBytes( array<Byte>^bytes );

int main()
{

   // Create instances of UTF32Encoding, with the byte order mark and without.
   UTF32Encoding ^ u32LeNone = gcnew UTF32Encoding;
   UTF32Encoding ^ u32BeNone = gcnew UTF32Encoding( true,false );
   UTF32Encoding ^ u32LeBom = gcnew UTF32Encoding( false,true );
   UTF32Encoding ^ u32BeBom = gcnew UTF32Encoding( true,true );

   // Display the preamble for each instance.
   PrintHexBytes( u32LeNone->GetPreamble() );
   PrintHexBytes( u32BeNone->GetPreamble() );
   PrintHexBytes( u32LeBom->GetPreamble() );
   PrintHexBytes( u32BeBom->GetPreamble() );
}

void PrintHexBytes( array<Byte>^bytes )
{
   if ( (bytes == nullptr) || (bytes->Length == 0) )
      Console::WriteLine( "<none>" );
   else
   {
      for ( int i = 0; i < bytes->Length; i++ )
         Console::Write( "{0:X2} ", bytes[ i ] );
      Console::WriteLine();
   }
}

/* 
This example displays the following output:
      FF FE 00 00
      <none>
      FF FE 00 00
      00 00 FE FF
*/

Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
Return to top
Show: