This documentation is archived and is not being maintained.

UnicodeEncoding.UnicodeEncoding(Boolean, Boolean) Constructor

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
)
public UnicodeEncoding (
	boolean bigEndian, 
	boolean byteOrderMark
)
public function UnicodeEncoding (
	bigEndian : boolean, 
	byteOrderMark : boolean
)
Not applicable.

Parameters

bigEndian

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

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 System;
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {

        // Create a UnicodeEncoding without parameters.
        UnicodeEncoding unicode = new UnicodeEncoding();

        // Create a UnicodeEncoding to support little-endian byte ordering
        // and include the Unicode byte order mark.
        UnicodeEncoding unicodeLittleEndianBOM = 
            new 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 =
            new 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 =
            new 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 =
            new UnicodeEncoding(true, false);
        // Compare this UnicodeEncoding to the UnicodeEncoding without parameters.
        DescribeEquivalence(unicode.Equals(unicodeBigEndianNoBOM));
    }

    public static void DescribeEquivalence(Boolean isEquivalent) {
        Console.WriteLine(
            "{0} equivalent encoding.", (isEquivalent ? "An" : "Not an")
        );
    }
}

import System.*;
import System.Text.*;
import System.Boolean;

class UnicodeEncodingExample
{
    public static void main(String[] args)
    {
        // Create a UnicodeEncoding without parameters.
        UnicodeEncoding unicode = new UnicodeEncoding();

        // Create a UnicodeEncoding to support little-endian byte ordering
        // and include the Unicode byte order mark.
        UnicodeEncoding unicodeLittleEndianBOM = new 
            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 = new 
            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 = new 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 = new 
            UnicodeEncoding(true, false);

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

    public static void DescribeEquivalence(boolean isEquivalent)
    {
        Console.WriteLine("{0} equivalent encoding.",
            (isEquivalent) ? "An" : "Not an");
    } //DescribeEquivalence
} //UnicodeEncodingExample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: