【问题标题】:Error: Can't convert from Dictionary to IDictionary错误:无法从 Dictionary 转换为 IDictionary
【发布时间】:2026-01-19 01:45:01
【问题描述】:
为什么会出现错误
错误 52 参数 1:无法从 'System.Collections.Generic.Dictionary>' 转换为 'System.Collections.Generic.IDictionary>'
Dictionary<string, List<string>> tempResultIDList = new Dictionary<string,List<string>>();
test(tempResultIDList);
public bool test(IDictionary<string,IList<string>> a)
{
return true;
}
【问题讨论】:
标签:
dictionary
idictionary
【解决方案1】:
Dictionary<string, List<string>> 实现 IDictionary<string, List<string>>,而您正尝试将其转换为 IDictionary<string, *I*List<string>>。这是不允许的,因为IDictionary<string, IList<string>> 有例如方法Add 接受IList<string> 的实例,而Dictionary<string, List<string>> 中的Add 方法不接受IList<string> 作为其输入。