Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a let clause using the dot notation style

Tags:

syntax

linq

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.

like image 723
Kevin Le - Khnle Avatar asked Mar 20 '10 20:03

Kevin Le - Khnle


People also ask

What is dot notation?

What is the Dot Notation? In simple words, the dot (.) notation is a way to access the attribute and methods of each method of instances of different object classes. It is usually preceded by the object instance while the right end of the dot notation contains the attributes and methods.

What is dot notation Objective C?

Dot Syntax Is a Concise Alternative to Accessor Method Calls As well as making explicit accessor method calls, Objective-C offers an alternative dot syntax to access an object's properties. Dot syntax allows you to access properties like this: NSString *firstName = somePerson. firstName; somePerson.


1 Answers

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);
like image 73
Jon Skeet Avatar answered Oct 12 '22 16:10

Jon Skeet