Delete list contents from another list

How to remove the contents of one list from another list?

+3
source share
3 answers
list1.RemoveAll(i => list2.Contains(i));
+9
source
List<object> result = anotherlist.Except(list).ToList();
+4
source

Here's a quick summary and tip by James post.

If you use List<T>, but myOtherListcontains many elements, you must convert it to Hashset<T> var set = new Hashset(myOtherList), so its solution should be much faster.

0
source

Source: https://habr.com/ru/post/1745767/


All Articles