1. What does query expression mean?
2. What does actually happen when we use query expressions?
3. How the C# 3.0 features are involved in query expressions?
The C# 3.0 introduced a new syntax which is called query expressions.
Example 1:
var customers = new [] {
new { Name = "John", Salary = 3.0 },
new { Name = "Ary", Salary = 3.5 },
new { Name = "Basya", Salary = 4d }
};
var query = from c in customers
where c.Salary > 3
orderby c.Name
select c.Name ;
This which is shown in first example is transformed into common C# syntax.
Example 2:
var func = customers
.Where(c => c.Salary > 3)
.OrderBy(c => c.Name)
.Select(c => c.Name);
So to get the result of those expressions we needed to use extension methods, lambda expressions to point out what the extension methods had to do and anonymous types and object initializers to define how to store result of the queries. Local type inference was used everywhere.