System.Text.ASCIIEncoding.GetByteCount Method

Calculates the number of bytes produced by encoding the characters in the specified string.

Syntax

public override int GetByteCount (string chars)

Parameters

chars
The string containing the set of characters to encode.

Returns

The number of bytes produced by encoding the specified characters.

Exceptions

TypeReason
ArgumentNullException chars is null.

Remarks

To calculate the exact array size required by ASCIIEncoding.GetBytes(string, int, int, Byte[], int) to store the resulting bytes, the application uses ASCIIEncoding.GetByteCount(Char[], int, int). To calculate the maximum array size, the application should use ASCIIEncoding.GetMaxByteCount(int). The ASCIIEncoding.GetByteCount(Char[], int, int) method generally allows allocation of less memory, while the ASCIIEncoding.GetMaxByteCount(int) method generally executes faster.

Requirements

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