LINQ Interview Question #52
How do you write an inner join using LINQ query syntax?
Joins, Grouping, Set & Quantifier Operators Mid-Level Intermediate
Quick Interview Answer
The join clause in query syntax performs an inner join by matching a key from the first source with a key from the second source. Only matching pairs are returned.
Detailed Explanation
The join clause in query syntax performs an inner join by matching a key from the first source with a key from the second source. Only matching pairs are returned.
Query syntax is often easy to read for joins because the relationship between the two sources is visible in one expression.
Code Example
var result =
from customer in customers
join order in orders
on customer.Id equals order.CustomerId
select new
{
customer.Name,
OrderId = order.Id
};