user1855005
user1855005

Reputation: 41

Extract Items from IEnumerable<ObservableCollection<T>> C#

I have:

IEnumerable<ObservableCollection<PointCollection>> rings = 
    from graphic 
    in e.FeatureSet 
    select ((Polygon)e.FeatureSet.Features).Rings;

I want to extract all the PointCollection's from each graphic and consolidate them into a single ObservableCollection. Something like this:

ObservableCollection<PointCollection> allRings = ?;

Is there a better way to iterate this without doing a bunch of nested ForEach statements?

Upvotes: 4

Views: 404

Answers (1)

McGarnagle
McGarnagle

Reputation: 102753

You could use SelectMany:

var allRings = new ObservableCollection<PointCollection>(
    rings.SelectMany(rings => rings)
);

Upvotes: 3

Related Questions