Find if listA contains any elements not in listB

Solution 1:

listA.Except(listB) will give you all of the items in listA that are not in listB

Solution 2:

if (listA.Except(listB).Any())

Solution 3:

listA.Any(_ => listB.Contains(_))

:)

Solution 4:

You can do it in a single line

var res = listA.Where(n => !listB.Contains(n));

This is not the fastest way to do it: in case listB is relatively long, this should be faster:

var setB = new HashSet(listB);
var res = listA.Where(n => !setB.Contains(n));