Posts

Showing posts from August, 2019

C# - Intersect and Except in Linq form

Something the intersect and except won't be enough for some comparisons. we will have to dig in for some particular type of values like ids, name, etc. Below is an example of this. Intersect in linq form- A.Intersect(B) => gives stuff in  both A and B             var intersect = A.Where(x => B.Select(y => y.Id).Contains(x.Id)).ToList(); Except in linq form- A.Except(B) => gives stuff in  A and NOT B             var intersect = A.Where(x => !B.Select(y => y.Id).Contains(x.Id)).ToList();