System.Text.Decoder.GetChars Method

When overridden in a derived class, decodes a sequence of bytes starting at the specified byte pointer and any bytes in the internal buffer into a set of characters that are stored starting at the specified character pointer. A parameter indicates whether to clear the internal state of the decoder after the conversion.

Syntax

[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetChars (byte* bytes, int byteCount, char* chars, int charCount, bool flush)

Parameters

bytes
A pointer to the first byte to decode.
byteCount
The number of bytes to decode.
chars
A pointer to the location at which to start writing the resulting set of characters.
charCount
The maximum number of characters to write.
flush
true to clear the internal state of the decoder after the conversion; otherwise, false.

Returns

The actual number of characters written at the location indicated by the chars parameter.

Remarks

Remember that the System.Text.Decoder object saves state between calls to Decoder.GetChars(Byte*, int, Char*, int, bool). 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 buffer size that GetChars requires to store the resulting characters, the application should use Decoder.GetCharCount(Byte*, int, bool).

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, Char*, int, bool, Int32@, Int32@, Boolean@) method. Decoder.GetChars(Byte*, int, Char*, int, bool) will throw an exception if the output buffer isn't large enough, but Decoder.Convert(Byte*, int, Char*, 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, Char*, int) topic for more comments.

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0