开发者

LINQ query finds subclass in an ObservableCollection of base class

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜