commandsWithAttributes

commandsWithAttributes

我有这本字典。

private Dictionary<string[], ICommand> commandsWithAttributes = new Dictionary<string[], ICommand>();


我需要通过键的一部分在commandsWithAttributes中找到元素。我的意思是:

"-?"-是我用来查找商品的钥匙。

({"-t","--thread"},ICommand)

({"-?","--help"},ICommand)

最佳答案

拜托,不要这样做。字典针对一键到一值搜索进行了优化。

我建议对单个值使用多个键如下:

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);

关于c# - 通过C#关键字典获取值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57369237/

10-10 09:05