Luis Garcia
Luis Garcia

Reputation: 1401

More LINQ syntax

I asked this question earlier and that helped a lot. Then I realized I also need a list of IDs of the List that is a property in that object. Basically I want to end up with a list of integers generated from each list in those objects. Any ideas? Thanks!

Upvotes: 0

Views: 296

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064014

var ids = (from x in outerList
          from y in x.List
          select y).ToList();

Or to avoid dups:

var ids = (from x in outerList
          from y in x.List
          select y).Distinct().ToList();

For info, this could also be written:

var ids = outerList.SelectMany(x => x.List).ToList();

or:

var ids = outerList.SelectMany(x => x.List).Distinct().ToList();

Upvotes: 4

Related Questions