UTF8Encoding.GetBytes Method (String)

Encodes the characters in a specified String object into a sequence of bytes.

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

public override byte[] GetBytes(
	string s


Type: System.String

The character string to encode.

Return Value

Type: System.Byte[]
A byte array that contains the encoded characters in the string specified by the s parameter.

To ensure that the encoded bytes are decoded properly when they are saved as a file or as a stream, you can prefix a stream of encoded bytes with a preamble. Inserting the preamble at the beginning of a byte stream (such as at the beginning of a series of bytes to be written to a file) is the developer's responsibility. The GetBytes method does not prepend a preamble to the beginning of a sequence of encoded bytes.

.NET Framework

Supported in: 1.1

XNA Framework

Supported in: 3.0, 2.0, 1.0