> ## 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# Into Clause

The `into` contextual keyword in C# is used within LINQ (Language Integrated Query) expressions to create a temporary identifier that stores the results of a `group`, `join`, or `select` clause. This mechanism, known as a query continuation, allows subsequent query operations to be evaluated against the newly formed sequence.

## Core Mechanics and Scope

The primary mechanical function of `into` is scope mutation. When `into` is applied after a `select` or `group` clause, it terminates the lexical scope of the preceding range variable. The new identifier introduced by `into` becomes the sole active range variable for the remainder of the query expression.

When used with a `join` clause, it alters the join type from an inner join to a group join, encapsulating the correlated elements into an `IEnumerable<T>` collection while keeping the outer range variable in scope.

## Syntactical Contexts

The `into` keyword is syntactically valid in three specific query expression structures.

### 1. Group Continuation (`group ... by ... into`)

When applied to a `group` clause, `into` captures the resulting `IGrouping<TKey, TElement>` objects. The original range variable is discarded.

```csharp theme={"dark"}
var query = from element in source
            group element by element.Category into groupedSequence
            // 'element' is now out of scope.
            // 'groupedSequence' is the active range variable of type IGrouping<TKey, TElement>.
            where groupedSequence.Count() > 5
            select groupedSequence.Key;
```

### 2. Group Join (`join ... in ... on ... equals ... into`)

When applied to a `join` clause, `into` instructs the compiler to perform a `GroupJoin` rather than a standard `Join`. It aggregates all matching elements from the inner sequence into a collection for each element in the outer sequence.

```csharp theme={"dark"}
var query = from outer in outerSource
            join inner in innerSource on outer.Id equals inner.OuterId into joinedSequence
            // 'outer' remains in scope.
            // 'inner' is out of scope.
            // 'joinedSequence' is an IEnumerable<TInner> containing all matches for the current 'outer'.
            select new { outer.Id, Matches = joinedSequence };
```

### 3. Select Continuation (`select ... into`)

When applied to a `select` clause, `into` captures the projected anonymous types or objects, allowing further filtering, grouping, or projection on the intermediate result.

```csharp theme={"dark"}
var query = from element in source
            select new { element.Id, TransformedValue = element.Value * 2 } into projectedSequence
            // 'element' is now out of scope.
            // 'projectedSequence' is the active range variable representing the anonymous type.
            where projectedSequence.TransformedValue > 100
            select projectedSequence;
```

## Compiler Translation

At compile time, the C# compiler translates query expressions containing `into` into chained standard query operator method calls.

* A `select ... into` or `group ... into` continuation is translated into sequential method chains (e.g., `.Select(...).Where(...)` or `.GroupBy(...).Where(...)`).
* A `join ... into` expression is explicitly mapped to the `Enumerable.GroupJoin` extension method, bypassing the `Enumerable.Join` method entirely.

<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>
