Encodes a set of characters from the specified string into the specified byte array.
- The string containing the set of characters to encode.
- The index of the first character to encode.
- The number of characters to encode.
- The byte array to contain the resulting sequence of bytes.
- The index at which to start writing the resulting sequence of bytes.
To calculate the exact array size required by UTF7Encoding.GetBytes(string, int, int, Byte, int) to store the resulting bytes, the application uses UTF7Encoding.GetByteCount(Char, int, int). To calculate the maximum array size, the application should use UTF7Encoding.GetMaxByteCount(int). The UTF7Encoding.GetByteCount(Char, int, int) method generally allows allocation of less memory, while the UTF7Encoding.GetMaxByteCount(int) method generally executes faster.
Data to be converted, such as data read from a stream, might be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application should use the System.Text.Decoder or the System.Text.Encoder provided by the UTF7Encoding.GetDecoder method or the UTF7Encoding.GetEncoder method, respectively.
System.Text.UTF7Encoding does not provide error detection. Invalid characters are encoded as a modified base 64 character. For security reasons, your applications are recommended to use System.Text.UTF8Encoding, System.Text.UnicodeEncoding, or System.Text.UTF32Encoding and enable error detection.