UnicodeEncoding.GetByteCount Method (String)
Calculates the number of bytes produced by encoding the characters in the specified String.
Assembly: mscorlib (in mscorlib.dll)
s is null (Nothing).
The resulting number of bytes is greater than the maximum number that can be returned as an integer.
Error detection is enabled, and s contains an invalid sequence of characters.
A fallback occurred (see Character Encoding in the .NET Framework for fuller explanation)
To calculate the exact array size required by GetBytes to store the resulting bytes, the application uses GetByteCount. To calculate the maximum array size, the application should use GetMaxByteCount. The GetByteCount method generally allows allocation of less memory, while the GetMaxByteCount method generally executes faster.
With error detection, an invalid sequence causes this method to throw a ArgumentException. Without error detection, invalid sequences are ignored, and no exception is thrown.
To ensure that the encoded bytes are decoded properly, the application should prefix encoded bytes with a preamble.