Mono Class Library: System.Text.Encoding Overview | Members

System.Text.Encoding.GetCharCount Method

Determines the exact number of characters that will be produced by decoding the specified range of the specified byte array.

public abstract int GetCharCount (byte[] bytes, int index, int count)

Parameters

bytes
The byte array to decode.
index
The first index in bytes to decode.
count
The number of bytes to decode.

Returns

A int containing the number of characters the next call to Decoder.GetChars(Byte[], int, int, Char[], int) will produce if presented with the specified range of bytes.

Exceptions

TypeReason
ArgumentNullExceptionbytes is null.
ArgumentOutOfRangeExceptionindex and count do not specify a valid range in bytes (i.e. (index + count) > bytes.Length).

Remarks

Operation
As described above.

Note to Inheritors
This method is overridden by types derived from System.Text.Encoding to return the appropriate number of bytes for the particular encoding.

Usage

Use Encoding.GetCharCount(Byte[]) to determine the exact number of characters that will be produced from converting a given range of bytes. An appropriately sized buffer for that conversion can then be allocated.

Alternatively, use Encoding.GetMaxCharCount(int) to determine the maximum number of characters that will be produced for a given number of bytes, regardless of the actual byte values. A buffer of that size can then be reused for multiple conversions.

Encoding.GetCharCount(Byte[]) generally uses less memory and Encoding.GetMaxCharCount(int) generally executes faster.

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0