开发者

LINQ query finds subclass in an ObservableCollection of base class

开发者 https://www.devze.com 2022-12-15 14:36 出处:网络
I\'m still getting my head around LINQ queries and the LINQ extension methods. 开发者_如何学运维

I'm still getting my head around LINQ queries and the LINQ extension methods. 开发者_如何学运维

Say I have a base class BaseA and subclass SubB with a property IsAwesome. I have an ObservableCollection<BaseA>. Is there some neat way I can grab a collection of only SubB classes where IsAwesome is true?


Or better:

myCollection.OfType<SubB>().Where(x => x.IsAwsome);


You can do:

myCollection.Where(x => x is SubB && (x as SubB).IsAwesome);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号