错误:无法从字典转换为IDictionary [英] Error: Can't convert from Dictionary to IDictionary
问题描述
为什么有错误
错误52参数1:不能从'System.Collections.Generic.Dictionary>'转换为'System.Collections.Generic.IDictionary>'
Why is there an error Error 52 Argument 1: cannot convert from 'System.Collections.Generic.Dictionary>' to '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;
}
推荐答案
字典< string,List< string>>
实现 IDictionary< string,List< string>>
到 IDictionary< string,* I * List< string>>
。这是不允许的,因为 IDictionary< string,IList< string>>
添加
接受 IList< string>
的实例,而添加$ c $您的
字典< string,list< string>>
中的c>方法不会接受 IList< string>
其输入。
Dictionary<string, List<string>>
implements IDictionary<string, List<string>>
, while you're trying to cast it to IDictionary<string, *I*List<string>>
. It is not allowed, because IDictionary<string, IList<string>>
has e.g. the method Add
accepting instance of IList<string>
, while Add
method in your Dictionary<string, List<string>>
won't accept IList<string>
as its input.
这篇关于错误:无法从字典转换为IDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!