gpt4 book ai didi

c# - 无法从 Dictionary 转换为 IDictionary

转载 作者:行者123 更新时间:2023-12-03 09:02:20 26 4
gpt4 key购买 nike

我正在尝试使用方法创建界面

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

然后像这样调用这个方法

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);

我预计它应该可以工作,但出现错误

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>>'  

为什么我这里不能使用接口(interface)IDictionary?我应该手动转换吗?

最佳答案

更改您的分配类型。

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));

关于c# - 无法从 Dictionary 转换为 IDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49325505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com