Reputation: 17068
I have an object Dictionary<int, Dictionary<int, Foo> >
on one side, and a function taking a IEnumerable<IEnumerable<Foo> >
on the other side.
What is the simpliest way to transform from one to the other in Linq, I can't think of something nice, all my tries ended with foreach loop...
Upvotes: 1
Views: 190
Reputation: 273844
The result from
var list = dict.Values.Select(kv => kv.Values);
is assignable to a parameter of type IEnumerable<IEnumerable<Foo> >
.
Upvotes: 2
Reputation: 1503799
This should do it:
return dictionary.Values.Select(nested => nested.Values);
Upvotes: 4
Reputation: 31249
Something like this:
var result= (
from d in dic
select
(
from values in d.Value
select values.Value
)
);
Upvotes: 1
Reputation: 56222
Use:
var result = dict.Select(d => d.Value.Select(i => i.Value));
Upvotes: 1