GetString Method

Encoding.GetString Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

When overridden in a derived class, decodes a sequence of bytes from the specified byte array into a string.

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

public virtual string GetString(
	byte[] bytes,
	int index,
	int count


Type: System.Byte []
The byte array containing the sequence of bytes to decode.
Type: System.Int32
The zero-based index of the first byte to decode.
Type: System.Int32
The number of bytes to decode.

Return Value

Type: System.String
A String containing the results of decoding the specified sequence of bytes.


bytes is null.


index or count is less than zero.


index and count do not denote a valid range in bytes.


A fallback occurred.

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.

The following example uses the GetString method to decode an array of UTF16-encoded bytes.

// Declare Byte array in little endian order.
Byte[] bytes = { 0x14, 0x04, 0x3e, 0x04, 0x31, 0x04, 0x40, 0x04, 
                 0x4b, 0x04, 0x39, 0x04, 0x20, 0x00, 0x34, 0x04, 
                 0x35, 0x04, 0x3d, 0x04, 0x21, 0x00};
Encoding enc = Encoding.GetEncoding("utf-16");
string output = enc.GetString(bytes, 0, bytes.Length);
outputBlock.Text += output + "\n";
// The example displays the following output:
//       Добрый ден!      

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2018 Microsoft