System.Text.UTF7Encoding.GetMaxCharCount Method

Calculates the maximum number of characters produced by decoding the specified number of bytes.

Syntax

public override int GetMaxCharCount (int byteCount)

Parameters

byteCount
The number of bytes to decode.

Returns

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

Remarks

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

UTF7Encoding.GetMaxCharCount(int) is a worst-case number, including the worst case for the currently selected System.Text.DecoderFallback. If a fallback is chosen with a potentially large string, UTF7Encoding.GetMaxCharCount(int) can return large values.

In most cases, this method returns reasonable numbers for small strings. For large strings, you might have to choose between using very large buffers and catching errors in the rare case that a more reasonable buffer is exceeded. You might also want to consider a different approach using erload:System.Text.UTF7Encoding.GetCharCount or erload:System.Text.Decoder.Convert.

UTF7Encoding.GetMaxCharCount(int) has no relation to UTF7Encoding.GetBytes(Char[], int, int, Byte[], int). If your application needs a similar function to use with UTF7Encoding.GetBytes(Char[], int, int, Byte[], int), it should use UTF7Encoding.GetMaxByteCount(int).

Note:

GetMaxCharCount(N) is not necessarily the same value as N* GetMaxCharCount(1).

Requirements

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