错误:无法从字典转换为IDictionary [英] Error: Can't convert from Dictionary to IDictionary

查看:343
本文介绍了错误:无法从字典转换为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> 的实例,而添加字典< 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆