Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert dictionary with List to IEnumerable

I have a dictionary:

Dictionary<String, List<Foo>> test = new Dictionary<String, List<Foo>>();

I then populate this dictionary hence why I need the list so I can call Add(). My problem is the function needs to return:

Dictionary<String, IEnumerable<Foo>>

Is there any easy way to do this without doing the obvious and looping through my original dictionary and doing it manually?

like image 470
DasDave Avatar asked Feb 11 '15 10:02

DasDave


1 Answers

return dictionary.ToDictionary(x => x.Key,x => x.Value.AsEnumerable())
like image 195
Selman Genç Avatar answered Sep 28 '22 09:09

Selman Genç