Encoding::GetBytes Method (String, Int32, Int32, array<Byte>, Int32)

When overridden in a derived class, encodes a set of characters from the specified string into the specified byte array.

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

No code example is currently available or this language may not be supported.

Parameters

s
Type: System::String
The string containing the set of characters to encode.
charIndex
Type: System::Int32
The zero-based index of the first character to encode.
charCount
Type: System::Int32
The number of characters to encode.
bytes
Type: array<System::Byte>
The byte array to contain the resulting sequence of bytes.
byteIndex
Type: System::Int32
The zero-based index at which to start writing the resulting sequence of bytes.

Return Value

Type: System::Int32
The actual number of bytes written into bytes.

ExceptionCondition
ArgumentNullException

s is nullptr.

-or-

bytes is nullptr.

ArgumentOutOfRangeException

charIndex or charCount or byteIndex is less than zero.

-or-

charIndex and charCount do not denote a valid range in chars.

-or-

byteIndex is not a valid index in bytes.

ArgumentException

bytes does not have enough capacity from byteIndex to the end of the array to accommodate the resulting bytes.

EncoderFallbackException

A fallback occurred (see Understanding Encodings for complete explanation).

To calculate the exact array size required by GetBytes 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 allocates less memory, while the GetMaxByteCount method generally executes faster.

If the data to be converted is available only in sequential blocks (such as data read from a stream) or if the amount of data is so large that it needs to be divided into smaller blocks, the application should use the Decoder or the Encoder provided by the GetDecoder method or the GetEncoder method, respectively, of a derived class.

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

The following code example determines the number of bytes required to encode a string or a range in the string, encodes the characters, and displays the resulting bytes.

No code example is currently available or this language may not be supported.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: