📎 Webclip
UTF8Encoding.Default != Encoding.UTF8 (.NET C#)
The post says that UTF8Encoding.Default does not create a UTF-8 encoder. It returns the operating system’s default ANSI encoding, and the same applies to ASCIIEncoding.Default, UnicodeEncoding.Default, UTF32Encoding.Default, and UTF7Encoding.Default because they all derive from System.Text.Encoding.
It points to System.Text.Encoding.Default as the place where this behavior is defined, and recommends using Encoding.ASCII, Encoding.UTF8, Encoding.UTF7, Encoding.UTF32, and Encoding.Unicode when an encoding needs to be named explicitly.
Reading notes#
UTF8Encoding.Defaultreturns the OS default ANSI encoding, not UTF-8.- The same pattern applies to
ASCIIEncoding.Default,UnicodeEncoding.Default,UTF32Encoding.Default, andUTF7Encoding.Default. System.Text.Encoding.Defaultis defined as the operating system’s current ANSI code page.- Use
Encoding.ASCII,Encoding.UTF8,Encoding.UTF7,Encoding.UTF32, andEncoding.Unicodeto refer to encodings explicitly.
