Where do Encoding. Default come from

heyangben 81 Reputation points
2022-04-25T09:31:30.043+00:00

I change the value of "change system locale" in region to any value,but "System.Text.Encoding. Default" value in c# always UTF8,Why?

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,141 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,312 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 29,101 Reputation points Microsoft Vendor
    2022-04-27T07:56:18.72+00:00

    Hi @heyangben ,
    According to the description in the document below

    • On .NET Core, the Default property always returns the UTF8Encoding.
    • In .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.

    https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.default?view=net-6.0
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Viorel 114.7K Reputation points
    2022-04-25T10:05:14.187+00:00

    I think that it is permanently set to UTF8: https://source.dot.net/#System.Private.CoreLib/Encoding.cs,83.

    In .NET Framework the behaviour is different: https://referencesource.microsoft.com/#mscorlib/system/text/encoding.cs,1425.