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

System.Text.Encoding.GetByteCount Method

Returns the number of bytes required to encode the specified char array. [Edit]

public virtual int GetByteCount (char[] chars)

Parameters

chars
The char array to encode. [Edit]

Returns

A int containing the number of bytes needed to encode chars. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionchars 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

Encoding.GetByteCount(Char[]) can be used to determine the exact number of bytes that will be produced from encoding the given array of characters. An appropriately sized buffer for that conversion can then be allocated.

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

Encoding.GetByteCount(Char[]) generally uses less memory and Encoding.GetMaxByteCount(int) generally executes faster.

[Edit]

Requirements

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