Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 682 Bytes

Better-lambdas.md

File metadata and controls

30 lines (26 loc) · 682 Bytes

Consider providing a predicate to the Cells/Rows/Columns methods instead of asking for all the object and then applying a .Where to them.

Not so good:

foreach (var row in worksheet.RowsUsed().Where(r => r.FirstCell().GetString() == "A"))
{
  // Do something with the row...
}

Best way:

using (var rows = worksheet.RowsUsed(r => r.FirstCell().GetString() == "A"))
{
  foreach (var row in rows)
  {
    // Do something with the row...
  }
}

Not so good:

var column = range.Columns().First(c => c.FirstCell().GetString() == "A");

Best way:

var column = range.FirstColumnUsed(c => c.FirstCell().GetString() == "A");