分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

System.Text.Encoding.Default在.net 及.netcore下不尽相同

发布时间:2023-09-06 02:29责任编辑:赖小花关键词:暂无标签
var data = System.Text.Encoding.Default.GetBytes("你好,China");Console.WriteLine(data.Length);

当面试官问你这打印出来是多少的时候,你一定要反问是在.net framework下还是.net core下。因为在.net framework下,打印是11。在.net core下打印是14。关于为何有此差异,MSDN上给出了解释。

The Default property in the .NET Framework
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. 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. Because all Default encodings based on ANSI code pages lose data, consider using the Encoding.UTF8 encoding instead. UTF-8 is often identical in the U+00 to U+7F range, but can encode characters outside the ASCII range without loss.
The Default property on .NET Core
On .NET Core, the Default property always returns the UTF8Encoding. UTF-8 is supported on all the operating systems (Windows, Linux, and Max OS X) on which .NET Core applications run.

System.Text.Encoding.Default在.net 及.netcore下不尽相同

原文地址:https://www.cnblogs.com/creekcloud/p/10240456.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved