> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Statement Lambda

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

```csharp theme={"dark"}
(input_parameters) => { sequence_of_statements; }
```

## 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`)**

```csharp theme={"dark"}
Action<string> processString = (input) => 
{
    string normalized = input.Trim().ToLower();
    Console.WriteLine(normalized);
};
```

**Value-returning Statement Lambda (`Func`)**

```csharp theme={"dark"}
Func<int, int, int> computeWithBranching = (x, y) => 
{
    int sum = x + y;
    if (sum < 0) 
    {
        return 0; // Explicit return required
    }
    return sum;   // Explicit return required
};
```

**Asynchronous Statement Lambda**

```csharp theme={"dark"}
Func<string, Task<int>> fetchAndMeasureAsync = async (url) => 
{
    using var client = new HttpClient();
    string result = await client.GetStringAsync(url);
    return result.Length;
};
```

**Parameter Discards in Statement Lambdas**

```csharp theme={"dark"}
// Using discards (_) for unused parameters in the delegate signature
Func<int, int, string> ignoreParameters = (_, _) => 
{
    string defaultState = "Unchanged";
    return defaultState;
};
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
