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 byte array. [Edit]

public virtual int GetCharCount (byte[] bytes)

Parameters

bytes
The byte array to decode. [Edit]

Returns

A int containing the number of characters produced by decoding bytes. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionbytes is null. [Edit]

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 byte array. 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.

[Edit]

Requirements

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