开发者

How to write a let clause using the dot notation style

开发者 https://www.devze.com 2022-12-23 08:25 出处:网络
Using the q开发者_如何学编程uery expression style, the let clause can be easily written.My question is how to use the dot notation style to write a let clause. Essentially it\'s a Select (in most case

Using the q开发者_如何学编程uery expression style, the let clause can be easily written. My question is how to use the dot notation style to write a let clause.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消