Returns the number of bytes required to encode the specified string.
- s
- The string to decode.
A int containing the number of bytes needed to encode s.
Type Reason ArgumentNullException s is null.
Operation
As described above.Note to Inheritors
This method is overridden by types derived from System.Text.Encoding to return the appropriate number of bytes for the particular encoding.Usage
Encoding.GetByteCount(Char[]) can be used to determine the exact number of bytes that will be produced from encoding the given string . An appropriately sized buffer for that conversion can then be allocated.
Alternatively, Encoding.GetMaxByteCount(int) can be used to determine the maximum number of bytes that will be produced from converting a given number of characters, regardless of the actual character values. A buffer of that size can then be reused for multiple conversions.
Encoding.GetByteCount(Char[]) generally uses less memory and Encoding.GetMaxByteCount(int) generally executes faster.
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0