Skip to content

Method syntax

Context: Method syntax uses extension methods like Where, Select, OrderBy with lambda expressions. It is more flexible and works with all operators.

var result = source.Where(item => condition).Select(item => expression);
var fruits = new[] { "apple", "banana", "cherry", "date" };
var longNames = fruits.Where(f => f.Length > 5)
.Select(f => f.ToUpper());
var result = numbers.Where(n => n > 2)
.OrderBy(n => n)
.Select(n => n * 2);

Data transformation pipelines: Method syntax is preferred in functional programming pipelines (e.g., ETL processes).

Example: In ASP.NET Core, method syntax is used extensively with IQueryable for database queries.