Query expressions

            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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s