c# - ReadKey while key is not pressed 做某事

标签 c# console console-application console.readkey readkey

我正在尝试运行我的代码,直到按下 Esc。因此我在我的控制台中使用 ReadKey

var input = Console.ReadKey();
do
{

} while (input.Key != ConsoleKey.Escape);

但在“ConsoleKey”处它表示,ConsoleKey 在“bool”中是不可能的。我该如何解决?或者我应该改用什么?

最佳答案

试试这个:

ConsoleKeyInfo input;
do
{
    input = Console.ReadKey();
} while (input.Key != ConsoleKey.Escape);

关于c# - ReadKey while key is not pressed 做某事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20845945/

相关文章:

linux - 是否可以将文件重定向到控制台程序,就像用户键入内容一样?

c# - .NET Core 中的 HttpClientHandler UseDefaultCredentials

c# - 是否有任何时区实际正确使用 TimeZoneInfo IsFixedDateRule?

php - Zend Framework 2 控制台路由

console - SurveyMonkey:通过控制台测试 api

C# |控制台应用 |如何让程序在执行下一行之前等待(时间以毫秒为单位)?

c# - 以编程方式在 WinForm 和控制台之间切换

c# - DbSet.Attach(entity) 与 DbContext.Entry(entity).State = EntityState.Modified

c# - 正则表达式仅允许字符第一次出现

c# - 从网络服务返回类型列表