我有这本字典。
private Dictionary<string[], ICommand> commandsWithAttributes = new Dictionary<string[], ICommand>();
Run Code Online (Sandbox Code Playgroud)
我需要commandsWithAttributes按部分键查找元素。我的意思是:
"-?" -是我用来查找商品的钥匙。
({"-t","--thread"},ICommand)
({"-?","--help"},ICommand) <-这是我需要找到的。
小智 6
拜托,不要这样做。字典针对一键到一值搜索进行了优化。
我建议对单个值使用多个键如下:
private Dictionary<string, ICommand> commandsWithAttributes = new Dictionary<string, ICommand>();
var command1 = new Command(); //Whatever
commandsWithAttributes.Add("-t", command1);
commandsWithAttributes.Add("--thread", command1);
var command2 = new Command(); //Whatever
commandsWithAttributes.Add("-?", command2);
commandsWithAttributes.Add("--help", command2);
Run Code Online (Sandbox Code Playgroud)