【发布时间】:2016-11-20 19:37:43
【问题描述】:
我有以下代码:
public static Dictionary<string, string[]> dict = new Dictionary<string, string[]>() {
"key1", { "value", "another value", "and another" }
};
这是不正确的。错误列表包含以下内容:
“Add”方法没有重载需要 3 个参数
没有给出与'Dictionary.Add(string, string[])'的所需形参'value'相对应的参数
我基本上只是想用预设值初始化我的字典。不幸的是,我不能使用代码初始化,因为我在一个静态类中工作,其中只有变量。
我已经尝试过这些东西:
... {"key1", new string[] {"value", "another value", "and another"}};... {"key", (string[]) {"value", "another value", "and another"}};
但我没有运气。任何帮助表示赞赏。
PS:如果我使用两个参数,日志会显示can't convert from string to string[]。
【问题讨论】:
标签: c# arrays dictionary