Search code examples
c#linqexceptremoveall

How to remove multiple elements from list based on another list without creating new instance?


I would like to know if its possible to remove multiple items from list based on another list without create new list instance?

I know its possible to use the except method but it does not remove the elements from the original list like the removeAll does, I would have happy to use the removeAll but it does not have an overload for passing a list as parameter (only for Predicate).

Here are some references (1,2,3) similar to my question.


Solution

  • try this:

    list1.RemoveAll(list => list2.Contains(list));