Why Encoding.ASCII != ASCIIEncoding.Default in C#?

2019-07-10 02:49发布

问题:

Why does Encoding.ASCII != ASCIIEncoding.Default in C#?

回答1:

This is because ASCIIEncoding derives from Encoding, where Default is defined as:

/// <summary>  
/// Gets an encoding for the operating  
/// system's current ANSI code page.  
/// </summary>  
public static System.Text.Encoding Default
{ get; }  

So ASCIIEndcoding.Default actually returns operating system’s default ANSI encoding.