Reading console input in MonoDevelop

狂风中的少年 提交于 2019-11-27 03:10:05

问题


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

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'

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.


回答1:


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

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 console under the Run > General tree.

alt text 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 is the correct and only answer.




回答2:


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



来源:https://stackoverflow.com/questions/652936/reading-console-input-in-monodevelop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!