In my specific example, I am using the Control.ModifierKeys Property and have something like:
if (Keyboard.Modifiers == ModifierKeys.Shift)
{
// some code
}
但是说我希望可以通过变量来更改“ Shift”,例如:
private string myKey = "Shift"
if (Keyboard.Modifiers == ModifierKeys.myKey)
{
// some code
}
我将如何做到这一点?
You can compare enums with strings by calling
ToString()
:不,您不能这样做,而是将变量值插入为枚举常量。您可以直接比较您的字符串键,例如