This documentation is archived and is not being maintained.

Decoder.Convert Method (Byte*, Int32, Char*, Int32, Boolean, Int32, Int32, Boolean)

Note: This method is new in the .NET Framework version 2.0.

Converts a buffer of encoded bytes to Unicode characters and stores the result in another buffer.

This method is not CLS-compliant.  The CLS-compliant alternative is Convert(Byte[],Int32,Int32,Char[],Int32,Int32,Boolean,Int32,Int32,Boolean).

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

public virtual void Convert (
	byte* bytes,
	int byteCount,
	char* chars,
	int charCount,
	bool flush,
	out int bytesUsed,
	out int charsUsed,
	out bool completed
J# does not support APIs that consume or return unsafe types.
JScript does not support APIs that consume or return unsafe types.



The address of a buffer that contains the byte sequences to convert.


The number of bytes in bytes to convert.


The address of a buffer to store the converted characters.


The maximum number of characters in chars to use in the conversion.


true to indicate no further data is to be converted; otherwise, false.


When this method returns, contains the number of bytes that were produced by the conversion. This parameter is passed uninitialized.


When this method returns, contains the number of characters from chars that were used in the conversion. This parameter is passed uninitialized.


When this method returns, contains true if all the characters specified by byteCount were converted; otherwise, false. This parameter is passed uninitialized.

Exception typeCondition


chars or bytes is a null reference (Nothing in Visual Basic).


charCount or byteCount is less than zero.


The output buffer is too small to contain any of the converted input. The output buffer should be greater than or equal to the size indicated by the GetCharCount method.

The Convert method is designed to be used in a loop to encode an arbitrary amount of input, such as data read from a file or stream, and store the output of the encoding operation in a fixed-sized buffer.

The current Decoder object maintains internal data and state information between iterations of the processing loop. Set the flush parameter to true to indicate that no further data is expected, and that the Decoder object can discard any unprocessed data and return to a default state. Any remaining processed data that is part of a logical unit, such as the high surrogate of a surrogate pair, is converted according to the current fallback settings.

The completed output parameter indicates whether all the data in the input buffer was converted and stored in the output buffer. The completed output parameter is false if the number of bytes specified by the byteCount parameter cannot be converted without exceeding the number of characters specified by the charCount parameter. In that situation, use the contents of the output buffer or provide a new output buffer, increment the bytes parameter by the number of bytes specified by the bytesUsed parameter, then call the Convert method again to process the remaining input.

The completed parameter can also be false, even though the bytesUsed and byteCount parameters are equal, if there is still data in the Decoder object that has not been stored in the bytes buffer.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0