shandianmao110
  • 英文系统下直接用WriteLine输出中文字符串会出现乱码
using static System.Console;

namespace WriteLineChineseError
{
    class Program
    {
        static void Main()
        {
            string s = "如果有一天不能相见那就不见";
            WriteLine(s);
        }
    }
}

在网上找到解决办法:
在输出代码前加一句

OutputEncoding = Encoding.Unicode;

并引入

using System.Text;

即可正确显示中文字符串

完整代码:

using System.Text;
using static System.Console;

namespace WriteLineChineseError
{
    class Program
    {
        static void Main()
        {
            OutputEncoding = Encoding.Unicode;
            string s = "如果有一天不能相见那就不见";
            WriteLine(s);
        }
    }
}

分类:

技术点:

相关文章:

  • 2022-02-23
  • 2021-12-05
  • 2022-01-23
  • 2021-06-23
  • 2021-09-08
  • 2022-02-08
  • 2021-06-19
猜你喜欢
  • 2021-10-19
  • 2021-08-17
  • 2022-12-23
  • 2021-11-07
  • 2021-07-06
  • 2022-12-23
  • 2021-12-16
相关资源
相似解决方案