开发者

How to make Linq extension methods available on ObservableCollection<T>

开发者 https://www.devze.com 2022-12-18 02:56 出处:网络
I\'ve written a class that inherits from ObservableCollection<T>. I would like to be able to use the LINQ extensions methods like FirstOrDefault, like what you may get if y开发者_运维知识库ou in

I've written a class that inherits from ObservableCollection<T>. I would like to be able to use the LINQ extensions methods like FirstOrDefault, like what you may get if y开发者_运维知识库ou inherit from an implementation of IEnumerable<T>, or List<T>. How would I accomplish this?


ObservableCollection is based on Collection which implements IEnumerable. You are probably just missing the using statement.

You might find it useful to use a VS addon like resharper which works all these things out for you, suggests fixes, improvements etc to your code (e.g. you type .First() and a tooltip appears saying "press alt+enter to add a reference to System.Linq") very very handy. I could never live without it now.

0

精彩评论

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

关注公众号