Why does Encoding.ASCII != ASCIIEncoding.Default in C#?
+7
A:
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.
Anton Gogolev
2009-05-08 06:40:05
So you're actually calling Encoding.Default, there is no ASCIIEncoding.Default. Resharper (and maybe FxCop) will warn you about that.
marklam
2009-05-08 08:09:27
Just to clarify further: The `Default` property is a static property that is always inherited from the `Encoding` class, no matter what encoding class you call it from.
awe
2010-09-16 08:07:52