对于所有四种可能的箭头键按键,我都有这个枚举
enum Direction{up=ConsoleKey.UpArrow, left=Consolekey.LeftArrow,...};
private ConsoleKeyInfo userSelect;
private bool mQuit;我就有了
public void getUserInput()
{
userSelect = Console.ReadKey()
if (userSelect.Key == ConsoleKey.Escape)
{
mQuit = true;
}
else if(userSelect.Key == "check if key press is value in enumeration")
{
//implementation
}
}我不能计算出检查“如果按键是枚举中的值之一”的代码是什么,有什么想法吗?
发布于 2013-03-12 20:05:22
else if(Enum.IsDefined(typeof(Direction), userSelect.Key)) {
//Logic
}发布于 2013-03-12 20:14:01
您可以使用cast来解决此问题。
if (userSelect.Key == (ConsoleKey)myEnum)
{
}https://stackoverflow.com/questions/15360649
复制相似问题