Kevin Le - Khnle
Kevin Le - Khnle

Reputation: 10887

How to write a let clause using the dot notation style

Using the query expression style, the let clause can be easily written. My question is how to use the dot notation style to write a let clause.

Upvotes: 14

Views: 3219

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503290

Essentially it's a Select (in most cases) which introduces a transparent identifier - via an anonymous type which encapsulates all the currently specified range variables. For example, this query:

string[] names = { "Jon", "Mark" };

var query = from name in names
            let length = name.Length
            where length > 3
            select name + ": " + length;

is translated into something like this:

var query = names.Select(name => new { name, length = name.Length })
                 .Where(z => z.length > 3)
                 .Select(z => z.name + ": " z.length);

Upvotes: 19

Related Questions