Possible Duplicate:
How can I implement NotOfType<T> in LINQ that has a nice calling syntax?
I have a collection where I want to iterate over all objects that are not of type Foo
. Basically I'd like something opposite of OfType<Foo>()
. What would be the appropriate way to do this?
So far I've used:
var result = myList.Where(elem => !(elem is Foo));
Nothing wrong with your code.
If you want to reuse this code you could ecnapsulate this in an extension method as it is done for the OfType<Foo>()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With