Skip to content

Instantly share code, notes, and snippets.

View Leen-odeh3's full-sized avatar
๐Ÿ’Ž
Focusing

Leen Odeh Leen-odeh3

๐Ÿ’Ž
Focusing
View GitHub Profile
@jehugaleahsa
jehugaleahsa / LTT.md
Last active June 17, 2024 17:35
LINQ Tricks and Techniques

Learn to Love LINQ

I've been using LINQ for years and I've come to deeply respect it as a technology. Unfortunately it has not been adopted by the .NET community as much as I would have expected. I honestly believe it is the single one feature that gives C# a competitive edge over many of the other general-purpose languages out there today. This document will go over some of the tricks I have learned to make the most of LINQ's powerful features. Hopefully you'll learn at least one trick along the way.

Query vs Method syntax

Yup, you can write your queries as a series of method calls or you can use the query syntax. Method syntax is fine when you're first starting out, but query syntax is more expressive in the long run. My experience has been that operations such as where, select, join, group by and order by should be expressed using query syntax and "reduce" operations should be done in method syntax. Unavoidably, you sometimes have to use method calls inside of your queries simply because th