Sweetening the syntax with syntactic sugar
C# 3 introduced some new keywords in 2008 to make it easier for programmers with experience in SQL to write LINQ queries. This syntactic sugar is sometimes called the LINQ query comprehension syntax.
Note
The LINQ query comprehension syntax is limited in functionality. You must use extension methods to access all the features of LINQ.
Consider the following code:
var names = new string[] { "Michael", "Pam", "Jim", "Dwight", "Angela", "Kevin", "Toby", "Creed" }; var query = names .Where(name => name.Length > 4) .OrderBy(name => name.Length) .ThenBy(name => name);
Instead of writing the preceding code using extension methods and lambda expressions, you can write the following code using query comprehension syntax:
var query = from name in names where name.Length > 4 orderby name.Length, name select...