我有一个控制台应用程序,需要按Shift键才能继续。但是,每当我尝试执行代码(如下所示)时,它都会返回以下错误:
不能将类型'System.ConsoleModifiers'隐式转换为'System.ConsoleKeyInfo'
这是我的代码:
class MainScreen
{
static void Main(string[] args)
{
Console.WriteLine("Press Shift to continue.");
var shift = Console.ReadKey(true);
if(shift == ConsoleModifiers.Shift)
{
Console.WriteLine("Redirecting to next screen...");
}
}
}
答案 0 :(得分:-1)
尝试一下:
Console.WriteLine("Press Shift to continue.");
public void KeyPress(object sender, KeyPressEventArgs e)
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
Console.WriteLine("Redirecting to next screen..."); }
}
}