See Also: UTF32Encoding Members
Encoding is the process of transforming a set of Unicode characters into a sequence of bytes. Decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters.
The UTF32Encoding.GetByteCount(Char, int, int) method determines how many bytes result in encoding a set of Unicode characters, and the UTF32Encoding.GetBytes(string, int, int, Byte, int) method performs the actual encoding.
Likewise, the UTF32Encoding.GetCharCount(Byte, int, int) method determines how many characters result in decoding a sequence of bytes, and the UTF32Encoding.GetChars(Byte, int, int, Char, int) and UTF32Encoding.GetString(Byte, int, int) methods perform the actual decoding.
System.Text.UTF32Encoding corresponds to the Windows code pages 12000 (little endian byte order) and 12001 (big endian byte order).
The encoder can use the big endian byte order (most significant byte first) or the little endian byte order (least significant byte first). For example, the Latin Capital Letter A (code point U+0041) is serialized as follows (in hexadecimal):
Big endian byte order: 00 00 00 41
Little endian byte order: 41 00 00 00
It is generally more efficient to store Unicode characters using the native byte order. For example, it is better to use the little endian byte order on little endian platforms, such as Intel computers.
The UTF32Encoding.GetPreamble method retrieves an array of bytes that can include the byte order mark (BOM). If this byte array is prefixed to an encoded stream, it helps the decoder to identify the encoding format used.
For more information on byte order and the byte order mark, see The Unicode Standard at the tp://go.microsoft.com/fwlink/?LinkId=37123.
To enable error detection and to make the class instance more secure, the application should use the UTF32Encoding.#ctor constructor that takes a throwOnInvalidCharacters parameter, and set that parameter to true. With error detection, a method that detects an invalid sequence of characters or bytes throws a ArgumentException. Without error detection, no exception is thrown, and the invalid sequence is generally ignored.