C# / LINQ / get all elements of sub-collection matching a condition? -
i have :
observablecollection<x> x_collection = new observablecollection(); public class x { public x() { items = new observablecollection<y>(); for(int = 0; < 10; i++) { items.add(new y(i % 2 == 0)); } } public observablecollection<y> items {get; set;} } public class y { public y() : this(true) {} public y(bool y) { myproperty = y; } public bool myproperty { get; set; } }
how create linq query return ienumerable or observablecollection y elements have myproperty == true? realize it's easy question i'm pretty confused linq atm.
if possible i'd ask lambda-query - they're easier me understand
var result = items.where( y => y.myproperty ); var biggerresult = x_collection.selectmany( x => x.items.where( y => y.myproperty ) );
Comments
Post a Comment