This documentation is archived and is not being maintained.

Encoding.GetByteCount Method (Char*, Int32)

When overridden in a derived class, calculates the number of bytes produced by encoding a set of characters starting at the specified character pointer.

This method is not CLS-compliant.  

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)

[CLSCompliantAttribute(false)] 
[ComVisibleAttribute(false)] 
public virtual int GetByteCount (
	char* chars,
	int count
)
Not applicable.

Parameters

chars

A pointer to the first character to encode.

count

The number of characters to encode.

Return Value

The number of bytes produced by encoding the specified characters.

Exception typeCondition

ArgumentNullException

chars is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

count is less than zero.

EncoderFallbackException

A fallback occurred (see Understanding Encodings for complete explanation)

-and-

EncoderFallback is set to EncoderExceptionFallback.

To calculate the exact array size that GetBytes requires to store the resulting bytes, the application should use 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.

For a discussion of programming considerations for use of this method, see the Encoding class description.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: