英文:
latest vs code - simple console app to ask for number
问题
我有一个简单的控制台应用程序,要求用户输入两个数字。然而,当我尝试运行它时,我没有收到提示?这似乎很简单?
我尝试了以下两种方式:
dotnet new console
dotnet new console --use-program-main
// 有关更多信息,请参阅 https://aka.ms/new-console-template
Console.Write("第一个数字? ");
var number1 = Convert.ToInt16(Console.ReadLine());
Console.Write("第二个数字? ");
var number2 = Convert.ToInt16(Console.ReadLine());
在使用命令行并转到 bin 目录并在那里执行时,它表现如预期。
英文:
I have a simple console app that asks the user for 2 numbers. However, when I try to run it I'm not getting the prompts? This seems so simple?
I've tried both
dotnet new console
dotnet new console --use-program-main
// See https://aka.ms/new-console-template for more information
Console.Write("First number? ");
var number1 = Convert.ToInt16(Console.ReadLine());
Console.Write("Second number? ");
var number2 = Convert.ToInt16(Console.ReadLine());
When I use cmd line and goto bin and execute it there it behaves as expected.
答案1
得分: 1
The debug console (which is what you are selected on in your screenshot) doesn't accept any kind of input for a running program.
According to Microsoft Documentation:
The Debug Console doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal.
As this states, you need to use the integrated terminal is Visual Studio Code, or an external one. The documentation also states how to do this. To summarize:
- Open your launch.json file used for debugging.
- Change the
console
property to be eitherintegratedTerminal
orexternalTerminal
.
If you opt to use the integrated terminal, when you debug, switch to the "Terminal" tab, and you'll see your prompts:
英文:
The debug console (which is what you are selected on in your screenshot) doesn't accept any kind of input for a running program.
According to Microsoft Documentation:
> The Debug Console doesn't accept terminal input for a running program. To handle terminal input while debugging, you can use the integrated terminal (one of the Visual Studio Code windows) or an external terminal.
As this states, you need to use the integrated terminal is Visual Studio Code, or an external one. The documentation also states how to do this. To summarize:
- Open your launch.json file used for debugging.
- Change the
console
property to be eitherintegratedTerminal
orexternalTerminal
.
If you opt to use the integrated terminal, when you debug, switch to the "Terminal" tab, and you'll see your prompts:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论