【发布时间】:2021-06-24 01:43:26
【问题描述】:
我在代码中使用字典如下:
var allValues = new Dictionary<string, int>();
while (//condition))
{
response = // call to a method that returns some values of type Dictionary<string, int>
allValues.Add(response);
}
当我使用 .Add 时,出现以下错误:
我错过了什么?
【问题讨论】:
-
从
response迭代键值对以添加到allValues或allValues = response;。 -
你不能将字典添加到字典中,你应该从响应中获取键和值并添加
-
已更新:
allValues = response;,此解决方案可能不正确,因为它位于循环内部,并且每次循环迭代都会被覆盖。 -
您的屏幕截图显示了带有两个预期参数的方法签名。但是您改为传递单个 Dictionary 参数。
标签: c# dictionary