The core Encoding.GetBytes and Encoding.GetChars methods require the caller to provide the destination buffer and ensure that the buffer is large enough to hold the entire result of the conversion. Decoders and encoders are obtained using the Encoding.GetDecoder and Encoding.GetEncoder methods. Decoders and encoders allow sequential blocks of data to be converted and they maintain the state required to support conversions of data that spans adjacent blocks. When the data to be converted is only available in sequential blocks (such as data read from a stream) or when the amount of data is so large that it needs to be divided into smaller blocks, an application can use a Decoder or an Encoder to perform the conversion. The Encoding.GetBytes and Encoding.GetChars methods maintain no state between conversions. Through an encoding, the Encoding.GetBytes method is used to convert arrays of Unicode characters to arrays of bytes, and the Encoding.GetChars method is used to convert arrays of bytes to arrays of Unicode characters. Applications can initialize new instances of Encoding objects through the ASCIIEncoding, UnicodeEncoding, UTF7Encoding, and UTF8Encoding classes. An application can use the properties of this class such as Encoding.ASCII, Encoding.Default, Encoding.Unicode, Encoding.UTF7, and Encoding.UTF8 to obtain encodings. This is also useful when the amount of data is so large that it needs to be divided into smaller blocks. When the data to be converted is only available in sequential blocks (such as data read from a stream), an application can use a Decoder or an Encoder to perform the conversion.
Use the Encoding.GetEncoding method with a code page or name parameter to obtain other encodings. This encoding supports all Unicode character values, and can also be accessed as code page 65001. The UTF8Encoding class encodes Unicode characters using the UTF-8 encoding (UTF-8 stands for UCS Transformation Format, 8-bit form).
This encoding supports all Unicode character values, and can also be accessed as code page 65000. The UTF7Encoding class encodes Unicode characters using the UTF-7 encoding (UTF-7 stands for UCS Transformation Format, 7-bit form). Both little-endian (code page 1200) and big-endian (code page 1201) byte orders are supported. The UnicodeEncoding class encodes each Unicode character as two consecutive bytes. This encoding only supports character values between U+0000 and U+007F. The ASCIIEncoding class encodes Unicode characters as single 7-bit ASCII characters. Remarks Methods are provided to convert arrays and strings of Unicode characters to and from arrays of bytes encoded for a target code page.Ī number of Encoding implementations are provided in the System.Text namespace, including: This type is safe for multithreaded operations.