Back to course

LINQ Method Syntax vs Query Syntax

C# Zero to Hero: Comprehensive Programming Masterclass

Method Syntax in LINQ

While Query syntax looks like SQL, Method syntax uses extension methods and Lambda expressions.

Example

csharp // Method Syntax (More popular) var evens = numbers.Where(n => n % 2 == 0).ToList();

// Query Syntax var evens2 = from n in numbers where n % 2 == 0 select n;

Method syntax is often more powerful as it allows chaining of operations like .OrderBy() or .Select() easily.