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.
精彩评论