UTF8Encoding.GetByteCount Method (String)
Calculates the number of bytes produced by encoding the characters in the specified String.
Assembly: mscorlib (in mscorlib.dll)
chars is null.
The resulting number of bytes is greater than the maximum number that can be returned as an integer.
Error detection is enabled, and chars contains an invalid sequence of characters.
A fallback occurred (see Character Encoding in the .NET Framework for complete 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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.