Compare two Lists for differences

This solution produces a result list, that contains all differences from both input lists.
You can compare your objects by any property, in my example it is ID.
The only restriction is that the lists should be of the same type:

var DifferencesList = ListA.Where(x => !ListB.Any(x1 => x1.id == x.id))
            .Union(ListB.Where(x => !ListA.Any(x1 => x1.id == x.id)));

Leave a Comment