TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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 ofinto 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
Theinto 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.
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.
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.
Compiler Translation
At compile time, the C# compiler translates query expressions containinginto into chained standard query operator method calls.
- A
select ... intoorgroup ... intocontinuation is translated into sequential method chains (e.g.,.Select(...).Where(...)or.GroupBy(...).Where(...)). - A
join ... intoexpression is explicitly mapped to theEnumerable.GroupJoinextension method, bypassing theEnumerable.Joinmethod entirely.
Master C# with Deep Grasping Methodology!Learn More





