Error: Can't convert from Dictionary to IDictionary

血红的双手。 提交于 2019-12-01 07:42:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!