C# ASCIIEncoding GetPreamble
Description
ASCIIEncoding GetPreamble
When overridden in a derived
class, returns a sequence of bytes that specifies the encoding used.
Syntax
ASCIIEncoding.GetPreamble
has the following syntax.
public virtual byte[] GetPreamble()
Returns
ASCIIEncoding.GetPreamble
method returns
Example
The following example determines the byte order of the encoding based on the preamble.
//from w ww .j a v a 2 s.c o m
using System;
using System.Text;
class GetPreambleExampleClass
{
static void Main()
{
Encoding unicode = Encoding.Unicode;
byte[] preamble = unicode.GetPreamble();
if(preamble.Length >= 2)
{
if(preamble[0] == 0xFE && preamble[1] == 0xFF)
{
Console.WriteLine("The Unicode encoder is encoding in big-endian order.");
}
else if(preamble[0] == 0xFF && preamble[1] == 0xFE)
{
Console.WriteLine("The Unicode encoder is encoding in little-endian order.");
}
}
}
}
The code above generates the following result.