C# 在 MonoDevelop 中读取控制台输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/652936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 11:56:21  来源:igfitidea点击:

Reading console input in MonoDevelop

c#monodevelop

提问by Joseph Burley

I am trying to a simple C# program that takes input and passes it as output. For instance, the output should be:

我正在尝试一个简单的 C# 程序,它接受输入并将其作为输出传递。例如,输出应该是:

What is your name?
{user input}
Your name is {user input}

The program is:

该计划是:

public static void Main(string[] args)
{
    Console.WriteLine("What is your name?");
    string name = Console.ReadLine();
    Console.WriteLine("Your name is: " + name);
    Console.ReadKey();
}

This is enclosed in a class called 'MainClass'

这包含在一个名为“MainClass”的类中

Its output is:

它的输出是:

What is your name?
Your name is:

Why is this not working and how can I make it work?

为什么这不起作用,我该如何使它起作用?

P.S. I am using MonoDevelop and I added Console.ReadKey(); after the last WriteLine. No change.

PS 我正在使用 MonoDevelop 并添加了 Console.ReadKey(); 在最后一个 WriteLine 之后。没变。

回答by configurator

Works on my machine

在我的机器上工作

Is your problem that the program quits immediately after reading the console input? If so, then add a Console.ReadKey();after the last WriteLineso the program will wait for a keypress. Otherwise, I don't know what the problem is; I copy+pasted the code and it worked.

您的问题是程序在读取控制台输入后立即退出吗?如果是这样,则Console.ReadKey();在最后一个之后添加一个,WriteLine以便程序等待按键。否则,我不知道是什么问题;我复制+粘贴了代码并且它起作用了。

回答by Ray Womack

You are trying to type in the Application Output window in MonoDevelop and it is read-only.

您正在尝试在 MonoDevelop 中的应用程序输出窗口中键入,它是只读的。

You can configure MonoDevelop to automatically run the program at the command prompt by right clicking on the "options" menu item of your project and checking Run on external consoleunder the Run > Generaltree.

您可以通过右键单击项目的“选项”菜单项并Run on external consoleRun > General树下进行检查,将MonoDevelop 配置为在命令提示符下自动运行程序。

alt text http://psf.biz/public/monodevelop_run_on_external_console.jpg

替代文字 http://psf.biz/public/monodevelop_run_on_external_console.jpg

I guess the guy that gave me the -1 was blinded by that huge "Works on My Machine" emblem, nevertheless this isthe correct and only answer.

我猜那个给我 -1 的人被那个巨大的“Works on My Machine”标志蒙蔽了双眼,不过这正确且唯一的答案。