Effieciently validate multiple DataRows with return early option I'm looking for an efficient way to validate multiple rows originating from multiple .csv files. Below is the current code to accomplish that.
The validation logic is in the function ValidateRow(DataRow row) (not presented here).

I could think of an alternative with using Linq and performing batch.All( row =&gt; ValidateRow(row)) and adding the row to the InvalidRow property in ValidateRow. But I don't know if that is more efficient or not.

public bool ValidateBatch( IEnumerable&lt;DataRow&gt; batch, bool exitOnFirstError = false )
    {
      //return early if we find no datarows
      if( batch == null || batch?.Count() == 0 ) { logger.Error( MSG_NO_DATAROWS ); return false; }
      bool result = true;

      foreach( DataRow row in batch )
      {
        if( !ValidateRow( row )  )
        {
          result = false;
          // track invalid rows on a property (List&lt;DataRow&gt;)
          InvalidRows.Add( row );
          if( exitOnFirstError )
          {
            return result;
          }
        }  
      }
      return result;
    }
The if condition  

if( batch == null || batch?.Count() == 0 ) { logger.Error( MSG_NO_DATAROWS ); return false; }  


has some flaws:  


the Null-Conditional operator ? on batch?.Count() == 0 isn't needed, because you already check for batch == null  
If the passed IEnumerable&lt;DataRow&gt; isn't a Collection&lt;T&gt; the IEnumerable&lt;DataRow&gt; will be enumerated completely for calculating the Count.
Assume you have millions of items in that IEnumerable&lt;T&gt; guess how much time it takes to iterate twice (once for Count() and once for the foreach).  
Having multiple statements in a single line reduces the readability of the code.


A better way would be to use the Any() method like so  

if( batch == null || !batch.Any()) 
{ 
    logger.Error( MSG_NO_DATAROWS ); 
    return false; 
}