System.Text.Encoding.GetEncoding Method

Returns the encoding associated with the specified code page name.

Syntax

public static Encoding GetEncoding (string name)

Parameters

name
The code page name of the preferred encoding. Any value returned by the Encoding.WebName property is valid. Possible values are listed in the Name column of the table that appears in the System.Text.Encoding class topic.

Returns

The encoding associated with the specified code page.

Remarks

The fallback handler depends on the encoding type of name. If name is a code page or double-byte character set (DBCS) encoding, a best-fit fallback handler is used. Otherwise, a replacement fallback handler is used. These fallback handlers may not be appropriate for your application. To specify the fallback handler used by the encoding specified by name, you can call the Encoding.GetEncoding(string, EncoderFallback, DecoderFallback) overload.

The GetEncoding method relies on the underlying platform to support most code pages. However, the .NET Framework natively supports some encodings.

Note:

The ANSI code pages can be different on different computers, or can be changed for a single computer, leading to data corruption. For the most consistent results, applications should use Unicode, such as UTF-8 (code page 65001) or UTF-16, instead of a specific code page.

For a list of code pages, see the System.Text.Encoding class topic. The application uses the Encoding.GetEncodings method to get a list of all encodings.

Encoding.GetEncoding(int) returns a cached instance with default settings. The application should use the constructors of derived classes to get an instance with different settings. For example, the System.Text.UTF32Encoding class provides a constructor that lets you 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