Is there a nicer way of doing the following: I need a check for null to happen on file.Headers before proceeding with the loop
if (file.Headers != null
Using Null-conditional Operator and ForEach() which works faster than standard foreach loop. You have to cast the collection to List though.
listOfItems?.ForEach(item => // ... );