首页 > 解决方案 > vscode中的Console.ReadLine出现问题

问题描述

大家好,我正在编写我的第一个程序,并且我选择了 C#。我正在尝试在多项选择测验的开头写一个小对话。根据 youtube 视频和论坛,我应该能够执行 WriteLine,然后执行空白 ReadLine,并且在输入任何内容后程序应该继续。但是当我向它提供输入时,它只会放下一行并继续等待提示。这是vscode引起的问题吗?此外,我只是在修改基本的 hello world 脚本。这是一些代码。谢谢。

using System;

namespace C_
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("In 5 seconds the teacher will begin to speak...");
            Console.ReadLine();
            Console.WriteLine("You will be tested for aptitude in the realm of being a worthy human.");
            Console.ReadLine();
        }
    }
}

标签: c#

解决方案


这是 Visual Studio Code 环境的问题。contains 设置将launch.json控制您的应用程序的执行方式。

默认情况下,属性:“console”设置为值“internalConsole”。所以它看起来像这样:
“console”:“internalConsole”

为了使用Console.ReadLine();Console.ReadKey();更改为:
“console”:“integratedTerminal”

然后在调试时切换到下方面板中的“终端”。

为了“自动”切换到“终端”面板,添加:
“internalConsoleOptions”:“neverOpen”


推荐阅读