C# UnicodeEncoding GetPreamble

Description

UnicodeEncoding GetPreamble Returns a Unicode byte order mark encoded in UTF-16 format, if the constructor for this instance requests a byte order mark.

Syntax

UnicodeEncoding.GetPreamble has the following syntax.


public override byte[] GetPreamble()

Returns

UnicodeEncoding.GetPreamble method returns

Example


using System;//from ww  w.j a  v a 2  s .  c o m
using System.Text;

class UnicodeEncodingExample {
    public static void Main() {
        Byte[] byteOrderMark;

        byteOrderMark = Encoding.Unicode.GetPreamble();
        Console.WriteLine("Default (little-endian) Unicode Preamble:");
        foreach (Byte b in byteOrderMark) {
            Console.WriteLine("[{0}]", b);
        }

        UnicodeEncoding bigEndianUnicode = new UnicodeEncoding(true, true);
        byteOrderMark = bigEndianUnicode.GetPreamble();
        foreach (Byte b in byteOrderMark) {
            Console.Write("[{0}]", b);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding