How to check if a List's value is contained within another List?

Hi guys i'm relatively new to LINQ so not the greatest of knowledge but i'm pretty sure this can be done using it.

I have two lists, a list of propertyAppliances and a list of engineerSkillsets.

The propertyAppliance object has an appliance sub-object with an applianceTypeId

The engineerSkillset object simply has this applianceTypeId.

I need to check if there is an appliance in that list that has an applianceTypeId that does not exist within the list of engineer skillsets.

Much appreciated!

Jon Skeet
people
quotationmark

If you only want to know whether there are any, I'd use:

if (propertyAppliances.Select(pa => pa.Appliance.TypeId)
                      .Except(engineers.Select(eng => eng.ApplianceTypeId))
                      .Any())

This effectively creates a set of appliance types from propertyAppliances, removes any appliance types from the set from the engineers, and sees whether there's anything in the result. I'd expect this to be more efficient than the answers which check every engineer against every appliance.

people

See more on this question at Stackoverflow