The maximum number of bytes produced by encoding the specified number of characters.
Type Reason ArgumentOutOfRangeException charCount < 0.
The ASCIIEncoding.GetByteCount(Char[], int, int) method calculates the exact array size required by the ASCIIEncoding.GetBytes(string, int, int, Byte[], int) method to store the resulting bytes, whereas the ASCIIEncoding.GetMaxByteCount(int) method calculates the maximum array size. The ASCIIEncoding.GetByteCount(Char[], int, int) method generally allocates less memory, but the ASCIIEncoding.GetMaxByteCount(int) method generally executes faster.
ASCIIEncoding.GetMaxByteCount(int) is a worst-case number, including the worst case for the currently selected System.Text.EncoderFallback. If you choose a replacement fallback with a potentially large string, ASCIIEncoding.GetMaxByteCount(int) can return large values.
The ASCIIEncoding.GetMaxByteCount(int) method considers potential leftover surrogates from a previous encoding operation. As a result, if the System.Text.ASCIIEncoding object uses the default replacement fallback, or if a custom replacement fallback has been defined with a single possible fallback character, the method returns charCount + 1. If the System.Text.ASCIIEncoding object uses a replacement fallback with more than one possible fallback character, the method returns n * (charCount + 1), where n is the maximum number of fallback characters.
ASCIIEncoding.GetMaxByteCount(int) has no relation to ASCIIEncoding.GetChars(Byte[], int, int, Char[], int). If your application needs a similar function to use with ASCIIEncoding.GetChars(Byte[], int, int, Char[], int), it should use ASCIIEncoding.GetMaxCharCount(int).
GetMaxByteCount(N) is not necessarily the same value as N* GetMaxByteCount(1).