Conclusion
Review what you learned in this course
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
, andselect
. - LINQ has methods to filter and transform collections like
Where
andSelect
. It also has methods to check for the content of collections likeAny
andAll
, to group elements and sort collections likeGroupBy
andOrderBy
, and to select a subset of collections likeFirst
,Last
,Take
, andSkip
. - 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
andDistinctBy
, new overloads likeTake
with ranges, andFirstOrDefault
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 1400+ tech skills courses.