How to compare and remove items from lists in C#

I am new to c# development. I want to compare and remove list items that already exist in another list. Is there any built in method to do that instead of doing it using loop?

>Solution :

var list1 = { /* first list */ };
var list2 = { /* second list to remove from first */ };

list1 = list1.Except(list2).ToList();

Leave a Reply