LINQ in C# tutorial

Learn how to filter, sort, group, and transform data with LINQ in C#.

Start the course

Course contents

Getting Started

  1. 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.
  2. LINQ Data Sources — Query collections, XML documents and database tables with the same query style, and choose the right provider for each.

Query Operators

  1. Filtering Operators — Keep only the items you want with Where and OfType, combine conditions, and build filters that change while the program runs.
  2. 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.
  3. Sorting Operators — Order results by any field, break ties with ThenBy, and write your own comparison rule when the natural order is wrong.
  4. 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.
  5. 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

  1. Element Operators — Return one item instead of a sequence, and choose between the throwing and the safe form of First, Last, Single and ElementAt.
  2. Set Operators — Remove duplicates and compare two collections with Distinct, Union, Intersect and Except, and control how equality is decided.
  3. Sequence Operators — Take and skip items by count or condition, build a paging query, generate a sequence from nothing, and join sequences together.
  4. 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

  1. 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.
  2. LINQ Cheat Sheet — Every operator in the course on one page: syntax templates, quick reference tables, common patterns and performance tips.
  3. 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.