LINQ Interview Question #6

What is method syntax in LINQ?

LINQ Fundamentals, Syntax, IEnumerable & IQueryable Junior Beginner

Quick Interview Answer

Method syntax uses extension methods such as Where, Select, OrderBy, GroupBy, Join, Any, and FirstOrDefault. It is also called fluent syntax because operators can be chained together.

Detailed Explanation

Method syntax uses extension methods such as Where, Select, OrderBy, GroupBy, Join, Any, and FirstOrDefault. It is also called fluent syntax because operators can be chained together.

Every standard LINQ operator is available through method calls, while query syntax supports only a subset of operations directly.

Code Example

var result = products
    .Where(p => p.Price > 100)
    .OrderBy(p => p.Name)
    .Select(p => p);