This is my type:
public class myType
{
public int Id { get; set; }
public string name { get; set; }
}
And there is 2 collection of this type:
List<myType> FristList= //fill ;
List<myType> Excludelist= //fill;
And I need to exclude Excludelist from FristList something like the following:
List<myType> targetList =
FirstList.Where(m=>m.Id not in (Excludelist.Select(t=>t.Id));
What is your suggestion about the exact lambda expression of the above query?
Three options. One without any changes:
Alternatively, either override
EqualsandGetHashCodeand use:Or write an
IEqualityComparer<MyType>which compares by IDs, and use:The second and third options are definitely nicer IMO, particularly if you need to do this sort of work in various places.