简体   繁体   English

无法从字典转换为IDictionary

[英]cannot convert from Dictionary to IDictionary

I'm trying to create interface with method 我正在尝试使用方法创建接口

void Import(int id, IDictionary<int, IDictionary<int, string>> items);

then call this method like 然后像这样调用此方法

Dictionary<int, Dictionary<int, string>> items = viewModel.Items
  .GroupBy(t => t.Number)
  .ToDictionary(t => t.Key, t => t.ToDictionary(x => x.LanguageId, x => x.Translation));


Import(id, items);

I expected that it should works but got an error 我期望它应该可以工作但是出现错误

cannot convert from 'System.Collections.Generic.Dictionary<int, System.Collections.Generic.Dictionary<int, string>>' to 'System.Collections.Generic.IDictionary<int, System.Collections.Generic.IDictionary<int, string>>'  

Why I can't use interface IDictionary here? 为什么我在这里不能使用接口IDictionary? Should I cast manually? 我应该手动投放吗?

Change your assigning type. 更改您的分配类型。

Dictionary<int, IDictionary<int, string>> items = viewModel.Items
  .GroupBy(t => t.Number)
  .ToDictionary(t => t.Key, t => (IDictionary<int, string>) t.ToDictionary(x => x.LanguageId, x => x.Translation));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM