I have 2 Lists: List<Car> newCars
and List<Car> oldCars
.
I need to use the List<Car> newCars
as the source of truth and return both Present and Absent cars in the List<Car>oldCars
list.
How can I do this?
My approach:
var present = newCars.Where(c => oldCars.All(w => w.Id != c.Id));
var absent = newCars.Where(c => oldCars.All(w => w.Id == c.Id));
I am quite new to LINQ, and I am not sure of the logic that I have used above.
Can someone help me out to get this working in a better and optimized way?
Can this be done in one single query and return 2 result sets (as tuples)?
I realize that running the same code with equals and not equals as above can be a costly approach.