Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Find Null Objects in List

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?

like image 948
griegs Avatar asked Feb 27 '23 19:02

griegs


1 Answers

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

return myLists.Count(ml => ml.Defects.Contains(null));
like image 199
mqp Avatar answered Mar 07 '23 22:03

mqp