Conclusion

Review what you learned in this course

We'll cover the following

Key points

Let’s review what we learned in this course. These are the main ideas we covered in this course:

  • Language-Integrated Query (LINQ) is a set of methods to work with collections in a declarative way.
  • LINQ is declarative and immutable.
  • A LINQ query isn’t evaluated until we iterate over its results.
  • We write LINQ queries using lambda expressions.
  • LINQ has a query-like syntax with keywords like from, where, and select.
  • LINQ has methods to filter and transform collections like Where and Select. It also has methods to check for the content of collections like Any and All, to group elements and sort collections like GroupBy and OrderBy, and to select a subset of collections like First, Last, Take, and Skip.
  • We can pass a condition directly to some LINQ methods instead of first filtering with Where.
  • With LINQ, we can refactor conditionals and object validation.
  • In .NET 6, LINQ has new methods like Chunk and DistinctBy, new overloads like Take with ranges, and FirstOrDefault with custom defaults.

Although we covered lots of subjects related to LINQ, we didn’t cover every single LINQ method available. We typically use only a few LINQ methods for 80% of the scenarios. The next time you have to work with collections in C#, remember you can write cleaner code with LINQ.

Happy coding!

Get hands-on with 1200+ tech skills courses.