LINQ (C#)
LINQ (Language Integrated Query) is a C# feature for querying and transforming collections using readable operations such as Where, Select, and OrderBy. It works on arrays, lists, databases, and more.
C#
LINQ comes in two styles: method syntax, which chains methods with lambdas like nums.Where(n => n > 2), and query syntax, which reads like SQL with from/where/select.
Most LINQ operations are lazy and return an IEnumerable<T>; you can call .ToList() to get a concrete list. LINQ methods live in the System.Linq namespace.
Syntax
collection.Where(x => condition).Select(x => transform)Examples
C#
int[] nums = { 1, 2, 3, 4, 5 };
var evens = nums.Where(n => n % 2 == 0).ToList();
Console.WriteLine(string.Join(", ", evens));Output:
2, 4Learn it in a lesson
- C#: LINQ →