Skip to main content
A statement lambda is a lambda expression in C# where the execution body is enclosed in a statement block { } containing one or more statements. Unlike expression lambdas, which evaluate and implicitly return a single expression, statement lambdas permit complex control flow, local variable declarations, and require an explicit return statement if the delegate signature expects a non-void return type.

Syntax

Technical Characteristics

  • Delegate Resolution: A statement lambda must be convertible to a compatible delegate type, typically from the Action family (for void returns) or the Func family (for value returns).
  • Return Semantics: If the target delegate type has a non-void return type, the statement block must contain an explicit return statement on all reachable code paths.
  • Expression Tree Incompatibility: Unlike expression lambdas, statement lambdas cannot be converted into expression trees (System.Linq.Expressions.Expression<TDelegate>). The C# compiler can only emit them as executable Intermediate Language (IL) bound to a delegate instance.
  • Lexical Scoping and Closures: The statement block defines a local scope. It can capture variables from the enclosing method (forming a closure), but variables declared within the { } block are strictly local to the lambda’s invocation.
  • Asynchronous Execution: Statement lambdas can be modified with the async keyword, allowing the use of await within the statement block. This resolves to an Action (if returning void), Func<Task>, or Func<Task<T>>.

Syntax Visualization

Void-returning Statement Lambda (Action)
Value-returning Statement Lambda (Func)
Asynchronous Statement Lambda
Parameter Discards in Statement Lambdas
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More