Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse of OfType in Linq? [duplicate]

Tags:

c#

linq

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));
like image 987
John-Philip Avatar asked Mar 19 '12 15:03

John-Philip


1 Answers

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>()

like image 55
Massimiliano Peluso Avatar answered Oct 23 '22 00:10

Massimiliano Peluso