LINQ Find null objects in a list

I have a List<MyList> objects.

MyList also has several lists in it and can be called List<Defect> .

List<Defect> may contain several defects, one or more of which may be empty.

How to return the number of MyList elements, where MyList.Defects contains a null object?

I know I can do foreach and check every element, but is there a LINQ way for this?

+4
source share
2 answers

How to return the number of MyList elements, where MyList.Defects contains a null object?

 return myLists.Count(ml => ml.Defects.Contains(null)); 
+4
source
 return myLists.Count(ml => ml.Defects.Any(d => d==null)); 
+4
source

Source: https://habr.com/ru/post/1313726/


All Articles