System.Text.ASCIIEncoding.GetString Method

Decodes a range of bytes from a byte array into a string.

Syntax

public override string GetString (byte[] bytes, int byteIndex, int byteCount)

Parameters

bytes
The byte array containing the sequence of bytes to decode.
bytes
The byte array containing the sequence of bytes to decode.
byteIndex
The index of the first byte to decode.
byteCount
The number of bytes to decode.

Returns

A string containing the results of decoding the specified sequence of bytes.

Exceptions

TypeReason
ArgumentNullException bytes is null.
ArgumentOutOfRangeException

byteIndex < 0.

-or-

byteCount < 0.

-or-

(bytes.Length - byteIndex) < byteCount.

Remarks

Data to be converted, such as data read from a stream, can be available only in sequential blocks. In this case, or if the amount of data is so large that it needs to be divided into smaller blocks, the application should use the System.Text.Decoder or the System.Text.Encoder provided by the ASCIIEncoding.GetDecoder method or the ASCIIEncoding.GetEncoder method, respectively.

System.Text.ASCIIEncoding does not provide error detection. Any byte greater than hexadecimal 0x7F is decoded as the Unicode question mark ("?").

Note:

For security reasons, your application is recommended to use System.Text.UTF8Encoding, System.Text.UnicodeEncoding, or System.Text.UTF32Encoding and enable error detection.

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0