Encoding.Default Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the default encoding for this .NET implementation.
public:
static property System::Text::Encoding ^ Default { System::Text::Encoding ^ get(); };
public static System.Text.Encoding Default { get; }
static member Default : System.Text.Encoding
Public Shared ReadOnly Property Default As Encoding
Property Value
The default encoding for this .NET implementation.
Remarks
Warning
Different computers can use different encodings as the default, and the default encoding can change on a single computer. If you use the Default encoding to encode and decode data streamed between computers or retrieved at different times on the same computer, it may translate that data incorrectly. In addition, the encoding returned by the Default property uses best-fit fallback to map unsupported characters to characters supported by the code page. For these reasons, using the default encoding is not recommended. To ensure that encoded bytes are decoded properly, you should use a Unicode encoding, such as UTF8Encoding or UnicodeEncoding. You could also use a higher-level protocol to ensure that the same format is used for encoding and decoding.
The Default property in .NET Framework
In .NET Framework on the Windows desktop, the Default property always gets the system's active code page and creates a Encoding object that corresponds to it. The active code page may be an ANSI code page, which includes the ASCII character set along with additional characters that vary by code page. Because all Default encodings based on ANSI code pages lose data, consider using the Encoding.UTF8 encoding instead. UTF-8 is often identical in the U+00 to U+7F range, but can encode characters outside the ASCII range without loss.
The Default property on .NET Core
On .NET Core, the Default property always returns the UTF8Encoding. UTF-8 is supported on all the operating systems (Windows, Linux, and macOS) on which .NET Core applications run.