C# UTF8Encoding GetPreamble
Description
UTF8Encoding GetPreamble
Returns a Unicode byte order
mark encoded in UTF-8 format, if the constructor for this instance requests
a byte order mark.
Syntax
UTF8Encoding.GetPreamble
has the following syntax.
public override byte[] GetPreamble()
Returns
UTF8Encoding.GetPreamble
method returns
Example
The following example demonstrates how to use the GetPreamble method to return the Unicode byte order mark encoded in UTF-8 format.
using System;/*from ww w .j av a 2 s .com*/
using System.Text;
class UTF8EncodingExample {
public static void Main() {
UTF8Encoding UTF8NoPreamble = new UTF8Encoding();
UTF8Encoding UTF8WithPreamble = new UTF8Encoding(true);
Byte[] preamble = UTF8NoPreamble.GetPreamble();
Console.WriteLine("UTF8NoPreamble");
Console.WriteLine(" preamble length: {0}", preamble.Length);
foreach (Object o in preamble) {
Console.WriteLine("[{0}]", o);
}
}
}
The code above generates the following result.