【发布时间】:2017-05-23 08:57:53
【问题描述】:
目前我正在使用此代码:
using System;
namespace Project
{
class MainClass
{
public static void Main (string[] args)
{
bool key = false;
while (key == false)
{
Console.WriteLine ("Loop");
}
}
}
}
这很好用,但我想让循环在按下一个键时停止。我试过这个:
using System;
namespace Project
{
class MainClass
{
public static void Main (string[] args)
{
bool key = false;
while (key == false)
{
Console.WriteLine ("Loop");
{
Console.ReadKey (true);
key = true
}
}
}
}
}
但这只是在按下一个键时继续循环。有什么解决办法吗?
【问题讨论】:
-
你的第二个代码没有编译,也没有继续循环(它只是阻塞按键)。