Encoding::GetEncoding Method

Returns the encoding associated with the specified name.

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

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

Parameters

name
Type: System::String
The name of the preferred encoding.

Return Value

Type: System.Text::Encoding
The object associated with the specified name.

ExceptionCondition
ArgumentException

name is not the name of a valid encoding.

The following table lists valid values for the name parameter. Except for "utf-16LE", they correspond to the strings returned by each encoding's WebName property.

Name

Encoding

utf-8

UTF8Encoding

utf-16

UnicodeEncoding (little-endian)

utf-16BE

UnicodeEncoding (big-endian)

utf-16LE

UnicodeEncoding (little-endian)

The name parameter is not case-sensitive. For example, the method returns a UnicodeEncoding object if name is either "utf-16" or 'UTF-16".

GetEncoding returns a cached instance with default settings. To get an instance with different settings, call the appropriate constructors of derived classes. For example, the UnicodeEncoding class provides a constructor that allows enabling of error detection.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 If you pass an invalid code page name to GetEncoding, the method throws PlatformNotSupportedException instead of ArgumentException.

The following example instantiates several encoding objects, including two that are returned by the GetEncoding method. It then checks them for equality.

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: