When overridden in a derived class, decodes a sequence of bytes from the specified byte array and any bytes in the internal buffer into the specified character array.
- bytes
- The byte array containing the sequence of bytes to decode.
- byteIndex
- The index of the first byte to decode.
- byteCount
- The number of bytes to decode.
- chars
- The character array to contain the resulting set of characters.
- charIndex
- The index at which to start writing the resulting set of characters.
The actual number of characters written into chars.
Type Reason ArgumentException chars does not contain sufficient space to store the decoded characters. ArgumentNullException bytes is null .
-or-
chars is null .
ArgumentOutOfRangeException byteIndex < 0.
-or-
byteCount < 0.
-or-
charIndex < 0.
-or-
byteIndex and byteCount do not specify a valid range in bytes (i.e. (byteIndex + byteCount ) > bytes.Length).
-or-
charIndex > chars.Length.
Remember that the System.Text.Decoder object saves state between calls to Decoder.GetChars(Byte[], int, int, Char[], int). When the application is done with a stream of data, it should set the flush parameter to true to make sure that the state information is flushed. With this setting, the decoder ignores invalid bytes at the end of the data block and clears the internal buffer.
To calculate the exact array size that GetChars requires to store the resulting characters, the application should use Decoder.GetCharCount(Byte[], int, int).
If GetChars is called with flush set to false, the decoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next decoding operation. The application should call GetCharCount on a block of data immediately before calling GetChars on the same block, so that any trailing bytes from the previous block are included in the calculation.
If your application is to convert many segments of an input stream, consider using the Decoder.Convert(Byte[], int, int, Char[], int, int, bool, Int32@, Int32@, Boolean@) method. Decoder.GetChars(Byte[], int, int, Char[], int) will throw an exception if the output buffer isn't large enough, but Decoder.Convert(Byte[], int, int, Char[], int, int, bool, Int32@, Int32@, Boolean@) will fill as much space as possible and return the bytes read and chars written. Also see the Encoding.GetChars(Byte[], int, int, Char[], int) topic for more comments.