I have 2 IEnumerable collections.
IEnumerable objectsToExcept
and
IEnumerable allObjects.
While the other answers are correct, I have to add that the result of the Except()
call can be assigned back to the original variable. That is,
allObjects = allObjects.Except(objectsToExcept);
Also keep in mind that Except()
will produce the set difference of the two collections, so if there are duplicates of the variables to be removed, they will all be removed.