System.Text.Encoder.GetByteCount Method

When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters from the specified character array. A parameter indicates whether to clear the internal state of the encoder after the calculation.

Syntax

public abstract int GetByteCount (char[] chars, int index, int count, bool flush)

Parameters

chars
The character array containing the set of characters to encode.
index
The index of the first character to encode.
count
The number of characters to encode.
flush
true to simulate clearing the internal state of the encoder after the calculation; otherwise, false.

Returns

The number of bytes produced by encoding the specified characters and any characters in the internal buffer.

Exceptions

TypeReason
ArgumentNullException chars is null.
ArgumentOutOfRangeException

Return value is greater than int.MaxValue.

-or-

index < 0.

-or-

count < 0.

-or-

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

Remarks

This method does not affect the state of the encoder.

To calculate the exact array size that Encoder.GetBytes(Char[], int, int, Byte[], int, bool) requires to store the resulting bytes, the application should use Encoder.GetByteCount(Char[], int, int, bool).

If GetBytes is called with flush set to false, the encoder stores trailing characters at the end of the data block in an internal buffer and uses them in the next encoding operation. The application should call GetByteCount on a block of data immediately before calling GetBytes on the same block, so that any trailing characters from the previous block are included in the calculation.

Requirements

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