
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
60
|
Chapter 2: Strings and Characters
However, for a byte[] to contain a Unicode representation of the letter S, it must
contain two elements. For example:
byte[] sourceArray = {83, 0};
The Intel architecture uses a little-endian encoding, which means that the first ele-
ment is the least-significant byte and the second element is the most-significant byte.
Other architectures may use big-endian encoding, which is the opposite of little-
endian encoding. The
UnicodeEncoding class supports both big-endian and little-
endian encodings. Using the
UnicodeEncoding instance constructor, you can
construct an instance that uses either big-endian or little-endian ordering. This is
accomplished by using one of the two following constructors:
public UnicodeEncoding (bool bigEndian, bool byteOrderMark);
public UnicodeEncoding (bool bigEndian, bool byteOrderMark,
bool throwOnInvalidBytes);
The first parameter, bigEndian, accepts a Boolean argument. Set this argument to
true to use big-endian or false to use little-endian.
In addition, you have the option to indicate whether a byte order mark preamble
should be generated so that readers of the file will know which endianness is in use.
See Also
See the “ASCIIEncoding Class” and “UnicodeEncoding Class” topics in the MSDN
documentation.
2.15 Converting Strings ...