问题
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;
}
回答1:
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.
来源:https://stackoverflow.com/questions/9334977/error-cant-convert-from-dictionary-to-idictionary