LINQ essentials
Query any sequence with the same handful of operators.
Where, Select, OrderBy, GroupBy β composable, lazy, and the same whether the source is a list, a file, or a database.
LINQ (Language-Integrated Query) gives every IEnumerable<T> a fluent set of operators. They compose into a pipeline that is lazy β nothing runs until you enumerate (e.g. ToList(), a foreach, or Count()).
The core verbs cover most needs: Where filters, Select projects, OrderBy/ThenBy sort, GroupBy buckets, and aggregates like Sum, Count, and Average fold a sequence to a value. Because the shape is uniform, the same query reads the same against in-memory objects or a remote database.
Try it 2 examples
Filter, project, order
C#introThe chained Where/OrderBy/Select yields the four sorted, doubled values 10, 14, 16, 18, while Count and Sum query the original nums β showing each operator works off its own source and only runs when enumerated.