Reputation: 646
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? Should I cast manually?
Upvotes: 2
Views: 5309
Reputation: 62213
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));
Upvotes: 5