System.Text.Encoding.GetEncoding Method

Returns the encoding associated with the specified code page name. Parameters specify an error handler for characters that cannot be encoded and byte sequences that cannot be decoded.

Syntax

public static Encoding GetEncoding (string name, EncoderFallback encoderFallback, DecoderFallback decoderFallback)

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.
encoderFallback
An object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
decoderFallback
An object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.

Returns

The encoding that is associated with the specified code page.

Remarks

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: 2.0.0.0, 4.0.0.0
Since: .NET 2.0