System.Text.UnicodeEncoding.GetCharCount Method

Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array.

Syntax

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

Parameters

bytes
The byte array containing the sequence of bytes to decode.
index
The index of the first byte to decode.
count
The number of bytes to decode.

Returns

The number of characters produced by decoding the specified sequence of bytes.

Exceptions

TypeReason
ArgumentNullException bytes is null.
ArgumentOutOfRangeException

index < 0.

-or-

count < 0.

-or-

index and count do not specify a valid range in bytes (i.e. (index + count) > bytes.Length).

Remarks

To calculate the exact array size required by UnicodeEncoding.GetChars(Byte[], int, int, Char[], int) to store the resulting characters, the application uses UnicodeEncoding.GetCharCount(Byte[], int, int). To calculate the maximum array size, the application should use UnicodeEncoding.GetMaxCharCount(int). The UnicodeEncoding.GetCharCount(Byte[], int, int) method generally allows allocation of less memory, while the UnicodeEncoding.GetMaxCharCount(int) method generally executes faster.

With error detection, an invalid sequence causes this method to throw a ArgumentException. Without error detection, invalid sequences are ignored, and no exception is thrown.

Requirements

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