Method syntax
Context: Method syntax uses extension methods like Where, Select, OrderBy with lambda expressions. It is more flexible and works with all operators.
Basic structure
Section titled “Basic structure”var result = source.Where(item => condition).Select(item => expression);Example
Section titled “Example”var fruits = new[] { "apple", "banana", "cherry", "date" };var longNames = fruits.Where(f => f.Length > 5) .Select(f => f.ToUpper());Chaining multiple operators
Section titled “Chaining multiple operators”var result = numbers.Where(n => n > 2) .OrderBy(n => n) .Select(n => n * 2);Real-world usage example
Section titled “Real-world usage example”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.