LINQ in C# tutorial
Learn how to filter, sort, group, and transform data with LINQ in C#.
Course contents
Getting Started
- Introduction to LINQ — Describe the data you want instead of looping to find it, write queries in both syntaxes, and understand when a query actually runs.
- LINQ Data Sources — Query collections, XML documents and database tables with the same query style, and choose the right provider for each.
Query Operators
- Filtering Operators — Keep only the items you want with Where and OfType, combine conditions, and build filters that change while the program runs.
- Projection Operators — Change the shape of each item with Select, flatten nested collections with SelectMany, and map objects into the types a screen or API needs.
- Sorting Operators — Order results by any field, break ties with ThenBy, and write your own comparison rule when the natural order is wrong.
- Join Operators — Match two collections on a shared key, keep items that have no match with a left outer join, and recognise an accidental cross join.
- Data Analysis Operators — Put items into groups, group by several keys, build a lookup table, and reduce a sequence to a single value.
Collection Operators
- Element Operators — Return one item instead of a sequence, and choose between the throwing and the safe form of First, Last, Single and ElementAt.
- Set Operators — Remove duplicates and compare two collections with Distinct, Union, Intersect and Except, and control how equality is decided.
- Sequence Operators — Take and skip items by count or condition, build a paging query, generate a sequence from nothing, and join sequences together.
- Conversion Operators — Turn a query into a list, array, set or dictionary, choose the right collection for what comes next, and answer yes-or-no questions.
Advanced & Reference
- Advanced LINQ — Control how LINQ decides two objects are equal, see how a query becomes SQL, run queries in parallel, and query data that arrives over time.
- LINQ Cheat Sheet — Every operator in the course on one page: syntax templates, quick reference tables, common patterns and performance tips.
- LINQ Reference — Every LINQ operator in one catalog, grouped by category, with an execution matrix, query and method syntax mapping, common exceptions and a best practices summary.