GetBytes Method (Char*, Int32, Byte*, Int32, Boolean)
Collapse the table of content
Expand the table of content

Encoder.GetBytes Method (Char*, Int32, Byte*, Int32, Boolean)

 

When overridden in a derived class, encodes a set of characters starting at the specified character pointer and any characters in the internal buffer into a sequence of bytes that are stored starting at the specified byte pointer. A parameter indicates whether to clear the internal state of the encoder after the conversion.

This API is not CLS-compliant.

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

[<SecurityCriticalAttribute>]
[<CLSCompliantAttribute(false)>]
[<ComVisibleAttribute(false)>]
abstract GetBytes : 
        chars:nativeptr<char> *
        charCount:int *
        bytes:nativeptr<byte> *
        byteCount:int *
        flush:bool -> int
[<SecurityCriticalAttribute>]
[<CLSCompliantAttribute(false)>]
[<ComVisibleAttribute(false)>]
override GetBytes : 
        chars:nativeptr<char> *
        charCount:int *
        bytes:nativeptr<byte> *
        byteCount:int *
        flush:bool -> int

Parameters

chars
Type: System.Char*

A pointer to the first character to encode.

charCount
Type: System.Int32

The number of characters to encode.

bytes
Type: System.Byte*

A pointer to the location at which to start writing the resulting sequence of bytes.

byteCount
Type: System.Int32

The maximum number of bytes to write.

flush
Type: System.Boolean

true to clear the internal state of the encoder after the conversion; otherwise, false.

Return Value

Type: System.Int32

The actual number of bytes written at the location indicated by the bytes parameter.

Exception Condition
ArgumentNullException

chars is null (Nothing).

-or-

bytes is null (Nothing).

ArgumentOutOfRangeException

charCount or byteCount is less than zero.

ArgumentException

byteCount is less than the resulting number of bytes.

EncoderFallbackException

A fallback occurred (see Character Encoding in the .NET Framework for fuller explanation)

-and-

Fallback is set to EncoderExceptionFallback.

Remember that the Encoder object saves state between calls to GetBytes. When the application is done with a stream of data, it should set the flush parameter to true in the last call to GetBytes to make sure that the state information is flushed and that the encoded bytes are properly terminated. With this setting, the encoder ignores invalid bytes at the end of the data block, such as unmatched surrogates or incomplete combining sequences, and clears the internal buffer.

To calculate the exact buffer size that GetBytes requires to store the resulting characters, the application should use GetByteCount.

If GetBytes is called with flush set to false, the encoder stores trailing bytes at the end of the data block in an internal buffer and uses them in the next encoding operation. The application should call GetByteCount on a block of data immediately before calling GetBytes on the same block, so that any trailing characters from the previous block are included in the calculation.

If your application is to convert many segments of an input stream, consider using the Convert method. GetBytes will throw an exception if the output buffer isn't large enough, but Convert will fill as much space as possible and return the chars read and bytes written. Also see the Encoding.GetBytes topic for more comments.

SecurityCriticalAttribute

Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2016 Microsoft