C#控制台正在输出框字符as''?&quot

发布于 2025-01-22 02:06:28 字数 1220 浏览 2 评论 0原文

我正在在ASCII中制作游戏,以娱乐,我遇到了一个问题,即以我期望的方式打印角色。 它不是正常打印的角色,而是打印出问号。 情况是:

预期结果:

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ PacGunMan         [_][^][X] ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃          Main Menu          ┃
┃    ━━━━━━━━━━━━━━━━━━━━━    ┃
┃                             ┃
┃          [1] Start          ┃
┃         [2] Settings        ┃
┃         [3] Credits         ┃
┃           [4] Exit          ┃
┃                             ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

我实际上得到的:

???????????????????????????????
? PacGunMan         [_][^][X] ?
???????????????????????????????
?          Main Menu          ?
?    ?????????????????????    ?
?                             ?
?          [1] Start          ?
?         [2] Settings        ?
?         [3] Credits         ?
?           [4] Exit          ?
?                             ?
???????????????????????????????

渲染源代码:

public static void Automatic(List<string> RenderItem) {
    Console.WriteLine("Rendering...");
    foreach (string Y in RenderItem) {   // The variable is named "Y" because Y-Axis
        Console.WriteLine(Y);
    }
}

I am making a game in ascii for fun and I have an issue where the characters are not printed in the way that i have expected them.
instead of the characters being printed normally, it instead prints out question marks.
here's the situation:

Expected Outcome:

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ PacGunMan         [_][^][X] ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃          Main Menu          ┃
┃    ━━━━━━━━━━━━━━━━━━━━━    ┃
┃                             ┃
┃          [1] Start          ┃
┃         [2] Settings        ┃
┃         [3] Credits         ┃
┃           [4] Exit          ┃
┃                             ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

What I actually got:

???????????????????????????????
? PacGunMan         [_][^][X] ?
???????????????????????????????
?          Main Menu          ?
?    ?????????????????????    ?
?                             ?
?          [1] Start          ?
?         [2] Settings        ?
?         [3] Credits         ?
?           [4] Exit          ?
?                             ?
???????????????????????????????

Rendering Source Code:

public static void Automatic(List<string> RenderItem) {
    Console.WriteLine("Rendering...");
    foreach (string Y in RenderItem) {   // The variable is named "Y" because Y-Axis
        Console.WriteLine(Y);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野稚 2025-01-29 02:06:28

C#,由于某些原因,在ASCII编码中打印字符。因此,我们需要将编码类型更改为UTF-8。

发生这种情况的原因之一可能是因为字符实际上可能没有以ASCII格式。但是在这种情况下,这是打印错误/问题,而不是字符的问题。

因此,这就是我们可以做到的:

Console.OutputEncoding = Encoding.UTF8; // Get C# to do this before outputting/printing.

因此,这是渲染源代码的外观:

public static void Automatic(List<string> RenderItem) {
    Console.OutputEncoding = Encoding.UTF8;
    Console.WriteLine("Rendering...");
    foreach (string Y in RenderItem) {
        Console.WriteLine(Y);
    }
}

C#, for some reason, prints characters in ASCII Encoding. So we need to change the encoding type to UTF-8.

One of the reasons why this happens is maybe because the characters may not actually be in an ASCII format. But in this case, it was the printing error/problem and not the characters' problem.

So here's how we can do that:

Console.OutputEncoding = Encoding.UTF8; // Get C# to do this before outputting/printing.

so here's how the Rendering Source Code should look like:

public static void Automatic(List<string> RenderItem) {
    Console.OutputEncoding = Encoding.UTF8;
    Console.WriteLine("Rendering...");
    foreach (string Y in RenderItem) {
        Console.WriteLine(Y);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文