c# - 没有给出对应于 Dictionary<string, string>.Add(string, string) 所需形式参数 'value' 的参数

标签 c# dictionary

<分区>

我尝试构造一个 Dictionary<string, Dictionary<string, string>> 的实例这样,

Dictionary<string,  Dictionary<string, string>> PredictiveTable =
            new Dictionary<string, Dictionary<string, string>>(){
                {"+", new Dictionary<string, string>() {"E","error"}},
                {"*", new Dictionary<string, string>() {"E","error"}},
                {"i", new Dictionary<string, string>() {"E","E->TK"}},
                {"(", new Dictionary<string, string>() {"E","E->TK"}},
                {")", new Dictionary<string, string>() {"E", "error"}},
                {"#", new Dictionary<string, string>() {"E", "error"}}
};

但是编译器只是告诉错误信息

CS7036 C# There is no argument given that corresponds to the required formal parameter 'value' of Dictionary<'string, string>.Add(string, string)

而且我之前尝试搜索错误提示,但就是找不到解决方法。

如果有人能帮助我,我将不胜感激。

最佳答案

Dictionary<string, Dictionary<string, string>> PredictiveTable =
            new Dictionary<string, Dictionary<string, string>>(){
                {"+", new Dictionary<string, string>() {{"E","error"}}},
                {"*", new Dictionary<string, string>() {{"E","error" }}},
                {"i", new Dictionary<string, string>() {{ "E","E->TK"}}},
                {"(", new Dictionary<string, string>() {{"E","E->TK"}}},
                {")", new Dictionary<string, string>() {{"E", "error"}}},
                {"#", new Dictionary<string, string>() {{ "E", "error"}}}
};

new Dictionary<string, string>()期望有一个 collection 的 KeyPairValues 用于初始化(就像您对外部 Dictionary 所做的那样)。你只通过了一个。

所以

new Dictionary<string, string>() {"E","error"}

成为

new Dictionary<string, string>() {
    {"E","error"}
}

关于c# - 没有给出对应于 Dictionary<string, string>.Add(string, string) 所需形式参数 'value' 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49873248/

相关文章:

C# 任务工厂超时

c# - 我应该在帖子中还是在 url 中存储 _method=PUT/DELETE

Javascript:从嵌套映射中抓取第一个元素

python - 当Python中的字典中找不到键值时,如何为字典中的键设置默认值

java - 字典或类似的数据结构,只存储最近的 n 个条目?

c# - 绘制不同粗细的线

c# - 如何让 Hangfire 作业调度程序错开我的 20 分钟间隔作业

c# - MongoDB 创建动态查询

JavaScript:根据下拉菜单更改链接值

python - Python 中的字典列表