使用Dictionary<TKey, TValue>:
类级别:
private readonly Dictionary<string, string> operations = new Dictionary<string, string>;
public ClassName() {
// put in constructor...
operations.Add("Subtract", "-");
// etc.
}
Run Code Online (Sandbox Code Playgroud)
在您的方法中,只需使用operations[e.Key.ToString()].
编辑:实际上,为了更高效率:
private readonly Dictionary<System.Windows.Input.Key, char> operations = new Dictionary<System.Windows.Input.Key, char>;
public ClassName() {
// put in constructor...
operations.Add(System.Windows.Input.Key.Subtract, '-');
// etc.
}
Run Code Online (Sandbox Code Playgroud)
在您的方法中,只需使用operations[e.Key].
| 归档时间: |
|
| 查看次数: |
10934 次 |
| 最近记录: |