Back to blog
documentation

FirstOrDefault

FirstOrDefault is the operation that returns first object from the sequence or null if the sequence is empty.

Syntax

FirstOrDefaultStage
  : 'firstOrDefault' '(' LambdaExpression? ')'  
  ;

Related tokens

[LambdaExpression](../expression/lambda)

FirstOrDefault examples

Find a table cell with the text 'Alex'. Returns null if not found.

select(tableCells) // PdfTableCell[]
    ->firstOrDefault((item) => item.Text() == 'Alex') // PdfTableCell?