Possible duplicate:How can I implement NotOfType <T> in LINQ that has good call syntax?
I have a collection where I want to iterate over all objects that are not of type Foo . Basically, I would like something opposite OfType<Foo>() . What would be a suitable way to do this?
Foo
OfType<Foo>()
So far I have used:
var result = myList.Where(elem => !(elem is Foo));
There is nothing wrong with the code.
If you want to reuse this code, you can ecnapsulate this in the extension method, as is done for OfType<Foo>()
Maybe like
var result = myList.Where(elem => (elem as Foo)==null)
Hope this helps.
Source: https://habr.com/ru/post/911109/More articles:JQuery UI Autocomplete - How to select an element and assign a label (rather than a value) in the input text - jqueryC ++ declares a function instead of calling a complex constructor - c ++Scala SBT project to create multiple modules for launch cans - scalaIs there a free tool capable of trimming unused code from the CLI assembly? - .netC ++ Binary tree error: query for member (X) in (Y) that belongs to non-class (Z) class - c ++Deleting a file using LFTP using variables - linux.csproj.user when checking in TFS - c #Is there a tool like mechanize for Android? - androidHow to fix regional settings for jQuery datepicker so that it works in Firefox and IE7? - jquery-uiInsert text after bookmark in openxml - c #All Articles