I really didn't expect that the visual studio 2022 version could not display Chinese correctly! I used JetBrains Rider before. It has a built-in console. When running, it will always display Chinese correctly, just like VSCode's built-in terminal.
I know it must be because the character code the code is running on doesn't match the terminal's settings. But this should not be manually modified by the user. . .
my code:
Console.WriteLine("Hello World!");
// here does not work
// output: ??,??!
Console.WriteLine("你好,世界!");
output:

extra information:

Maybe replacing the default console of visual studio with powershell can solve the problem?
thank you all
I found a temporary solution (as one line of code needs to be added):
In my case (windows 10), Visual Studio uses a console called "Windwos Console Host" as the default terminal, which doesn't seem to support utf-8
because when I added the following code:
Console.OutputEncoding = Encoding.UTF8;
the Chinese output changed from "question mark" to "strange symbols", so I deduce that the terminal used by Visual Studio Debug Console probably does not support UTF-8:

So I changed the default terminal to "windows terminal" in the settings of "windows terminal":

This time successfully printed Chinese ("windows terminal" must support utf-8):

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With