Q:

Using .Where clause and conditional to Filter Array

I have 2 IEnumerable lists that have a method called GetId() which returns an integer. 
IEnumerable oldBoats
IEnumerable updatedBoats

I want to compare both lists. If updatedBoats.getId() returns a unique Id compared to oldBoats, I want to add it to a list. 
So I did this: 
IEnumerable<Boat> newBoats = updatedBoats
    .Where(c => oldBoats
    .Any(d => d.GetId() != c.GetId())
    .ToList()

The current IDs for oldBoats and newBoats is [1, 2, 3, 4, 5]. I want to test the base case and this does not pass. The newBoats always returns a list for all the IDs when it should return none. Am I doing the ordering of c and d wrong? 

A:

How about this?
var newBoats = updatedBoats.Where(u => !oldBoats.Any(o => o.GetId() == u.GetId()));

A:

What this code does
IEnumerable<Boat> newBoats = updatedBoats.Where(c=> oldBoats.Any(d =>d.GetId() != c.GetId()).ToList()

roughly translates to: "give me all of the updated boats whose ID doesn't match at least one of the old boat IDs". That isn't what you want. The logic you want is "give me all of the updated boats whose ID doesn't match any of the old boat IDs", and that is correctly specified by @zeroef:
var newBoats = updatedBoats.Where(u => !oldBoats.Any(o => o.GetId() == u.GetId()));  
// This is O(o * n) for # of old boats * # of updates that are new boats, and something like O((o/2)*n) for # of old boats * number of updated old boats

That said, note my comment. This would be more efficiently implemented using a HashSet<T>:
// This is O(n) for # of updated boats
var newBoatIds = new HashSet<Int32>(updatedBoats.Select(b => b.GetId())); 
// This is O(n) for # of old boats
newBoatIds.ExceptWith(oldBoats.Select(b => b.GetId()));

This reduces the number of nested iterations significantly, and you'll see a difference if you have a lot of boats (and particularly if you have a lot of new boats in your update).
The HashSet approach works for IDs, but you can also make it work for entities themselves if you implement Equals() and GetHashcode() on the Boat class using the ID for comparison.

