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 編碼,例如UTF8EncodingUnicodeEncodingTo 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. 作用中的字碼頁可能包含字碼頁來設定以及不同的其他字元的 ASCII 字元的 ANSI 字碼頁。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 CoreDefault屬性一律會傳回UTF8EncodingOn .NET Core, the Default property always returns the UTF8Encoding. Utf-8 支援的所有作業系統 (Windows、 Linux 和最大 OS X) 上執行的.NET Core 應用程式。UTF-8 is supported on all the operating systems (Windows, Linux, and Max OS X) on which .NET Core applications run.

適用於