Encoding.GetEncoding Method (String, EncoderFallback, DecoderFallback)
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.
Assembly: mscorlib (in mscorlib.dll)
static member GetEncoding : name:string * encoderFallback:EncoderFallback * decoderFallback:DecoderFallback -> Encoding
- Type: System.String
An object that provides an error-handling procedure when a character cannot be encoded with the current encoding.
An object that provides an error-handling procedure when a byte sequence cannot be decoded with the current encoding.
Return ValueType: System.Text.Encoding
The encoding that is associated with the specified code page.
name is not a valid code page name.
The code page indicated by name is not supported by the underlying platform.
The GetEncoding method relies on the underlying platform to support most code pages. However, the .NET Framework natively supports some encodings.
In addition to the encodings that are intrinsically supported on a specific platform version of the .NET Framework, the GetEncoding(Int32) method returns any additional encodings that are made available by registering an EncodingProvider object.
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, you should use Unicode, such as UTF-8 (code page 65001) or UTF-16, instead of a specific code page.
GetEncoding returns a cached instance with default settings. You should use the constructors of derived classes to get an instance with different settings. For example, the UTF32Encoding class provides a constructor that lets you enable error detection.
Available since 10
Available since 2.0