UnicodeEncoding Constructor (Boolean, Boolean)


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

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

new : 
        bigEndian:bool *
        byteOrderMark:bool -> UnicodeEncoding


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).

Type: System.Boolean

true to specify that the GetPreamble method returns a Unicode byte order mark; otherwise, false. See the Remarks section for more information.

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


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

The byteOrderMark parameter controls the operation of the GetPreamble method. If true, the method returns a byte array containing the Unicode byte order mark (BOM) in UTF-16 format. If false, it returns a zero-length byte array. However, setting byteOrderMark to true does not cause the GetBytes method to prefix the BOM at the beginning of the byte array, nor does it cause the GetByteCount method to include the number of bytes in the BOM in the byte count.

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

No code example is currently available or this language may not be supported.

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