【发布时间】:2010-07-02 20:59:50
【问题描述】:
我想比较控制台中按下的键与左箭头键是否相等,这意味着按下的键是左箭头键,键将控制台的背景颜色更改为青色...
我不确定如何设置 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";
}
}
}
}
【问题讨论】:
标签: c# console-application keystrokes