views:

57

answers:

2

I have a List<MyList> of objects.

MyList also has in it several Lists and one might be called List<Defect>.

List<Defect> can contain multiple defects one or more of which might be null.

How can I return a count of MyList items where MyList.Defects contains a null object?

I know I can do a foreach and check every item but is there a LINQ way to do this?

+4  A: 

How can I return a count of MyList items where MyList.Defects contains a null object?

return myLists.Count(ml => ml.Defects.Contains(null));
mquander
+3  A: 
return myLists.Count(ml => ml.Defects.Any(d => d==null));
Joel Coehoorn
+1 Whilst I think this solution is probably easier to read, I like @mquander's solution a little better for its brevity. Thank you any way @Joel.
griegs