System.Text.UTF8Encoding.GetBytes Method

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

Syntax

public override byte[] GetBytes (string s)

Parameters

s
The character string to encode.

Returns

A byte array that contains the encoded characters in the string specified by the s parameter.

Exceptions

TypeReason
ArgumentExceptionError-checking is turned on for the current instance and s contains an invalid surrogate sequence.
ArgumentNullException s is null.

Remarks

If error-checking is turned off and an invalid surrogate sequence is detected, the invalid characters are ignored and are not encoded into the returned byte array, and no exception is thrown.

Note: This method overrides Encoding.GetBytes(Char[]).

Requirements

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