怎样让一个命令行程序按Esc退出

C#的命令行环境下, 写一个简单的halloworld
在运行之后按enter会重复输出helloworld
而不是自动退出 让用户按esc之后退出
是命令行!Console! 今天第一次用C#的命令行, 懵了

第1个回答  2008-11-29
在窗体属性里设置AcceptButton属性设为伱要的按钮,就可以实现在回车重复输出,设置CancelButton属性设为伱要的按钮,就可以实现在ESC退出的效果!
第2个回答  2008-11-29
static void Main(string[] args)
{
while (true)
{
if (Console.ReadKey().Key == ConsoleKey.Enter)
{
Console.WriteLine("hello world!");
}
else if (Console.ReadKey().Key == ConsoleKey.Escape)
{
break;
}
}
}本回答被提问者采纳
相似回答
大家正在搜