如何检查是否使用 ConsoleKeyInfo 按下了 2 个可能的键中的任何一个?
How to check if any of 2 possible keys is pressed with ConsoleKeyInfo?
我在使用 ConsoleKeyInfo 时遇到了一个非常愚蠢的问题。我想检查是否使用小键盘或常规顶部数字键输入了“1”。
ConsoleKeyInfo keyPressed;
keyPressed = Console.ReadKey();
if (keyPressed = ConsoleKey.D1 || keyPressed = ConsoleKey.NumPad1)
{ }
出于某种原因我不能使用“||”操作员。是否可以在 1 if 循环中以某种方式检查它而不使用 Console.ReadLine();
并强制用户按 enter 键?
我在使用 ConsoleKeyInfo 时遇到了一个非常愚蠢的问题。我想检查是否使用小键盘或常规顶部数字键输入了“1”。
ConsoleKeyInfo keyPressed;
keyPressed = Console.ReadKey();
if (keyPressed = ConsoleKey.D1 || keyPressed = ConsoleKey.NumPad1)
{ }
出于某种原因我不能使用“||”操作员。是否可以在 1 if 循环中以某种方式检查它而不使用 Console.ReadLine();
并强制用户按 enter 键?