我想比较控制台中按下的键与左箭头键是否相等,这意味着按下的键是左箭头键,键将控制台的背景颜色更改为青色...
我不确定如何设置 If 语句,因为我不知道如何在控制台中比较键。
using System;
namespace ConsolePaint
{
class MainClass
{
public static void Main (string[] args)
{
ConsoleKeyInfo keypress;
keypress = Console.ReadKey(); // read keystrokes
if ( keypress.KeyChar == ConsoleKey.LeftArrow )
{
Console.BackgroundColor = "Cyan";
}
}
}
}