Encoding.Default Encoding.Default Encoding.Default Encoding.Default Property

定義

取得此 .NET 實作的預設編碼。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; }
member this.Default : System.Text.Encoding
Public Shared ReadOnly Property Default As Encoding

屬性值

這個 .NET 執行的預設編碼方式。The default encoding for this .NET implementation.

備註

警告

不同的電腦可以使用不同的編碼方式做為預設值,而且預設的編碼方式可以在單一電腦上變更。Different computers can use different encodings as the default, and the default encoding can change on a single computer. 如果您使用Default編碼方式來編碼和解碼電腦之間的資料流程,或在同一部電腦上的不同時間進行串流處理,則可能會不正確地轉譯該資料。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. 此外, Default屬性所傳回的編碼會使用自動調整回溯,將不支援的字元對應到字碼頁所支援的字元。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. 為確保已正確解碼編碼的位元組,您應該使用 Unicode 編碼,例如UTF8Encoding或。 UnicodeEncodingTo 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.

.NET Framework 中的預設屬性The Default property in the .NET Framework

在 Windows 桌面上的 .NET Framework 中, Default屬性一律會取得系統的作用中字碼頁,並Encoding建立與其對應的物件。In the .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. 使用中的字碼頁可能是 ANSI 字碼頁,其中包括 ASCII 字元集以及因字碼頁而異的其他字元。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. 因為所有Default以 ANSI 字碼頁為基礎的編碼都會遺失資料, Encoding.UTF8請考慮改用編碼方式。Because all Default encodings based on ANSI code pages lose data, consider using the Encoding.UTF8 encoding instead. UTF-8 在 U + 00 到 U + 7F 範圍中通常都相同,但可以編碼 ASCII 範圍以外的字元,而不會遺失。UTF-8 is often identical in the U+00 to U+7F range, but can encode characters outside the ASCII range without loss.

.NET Core 上的預設屬性The Default property on .NET Core

在 .net Core 上, Default屬性一律UTF8Encoding會傳回。On .NET Core, the Default property always returns the UTF8Encoding. 在 .NET Core 應用程式執行所在的所有作業系統(Windows、Linux 和最大 OS X)上都支援 UTF-8。UTF-8 is supported on all the operating systems (Windows, Linux, and Max OS X) on which .NET Core applications run.

適用於