LINQ查询语法和推广方法 [英] Linq query syntax and extension methods

查看:184
本文介绍了LINQ查询语法和推广方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常喜欢的扩展方法,因为我觉得他们更容易阅读,但艾尔诺看到答案的这个问题我想知道最小的查询将如何看待与仅使用扩展方法?

I usually prefer the extension methods, because they i find them easier to read, but after seeing the answer by Erno to this question I was wondering how the minimum query would look with only extension methods used?

和更普遍的是有查询,你可以在一个表格创建而不是其他,或者都接近相同呢?

And more generally, are there queries that you can create in one form but not the other, or are both approaches equivalent?

推荐答案

有什么可以在其中离不开查询表达式进行查询表达式做 - 查询表达式只是翻译成非 - 查询表达式代码反正。有很多不能在查询表达式虽然写的查询...例如,使用选择过载,它提供索引,以及什么:

There's nothing you can do in query expressions which can't be done without query expressions - query expressions are just translated into non-query-expression code anyway. There are plenty of queries that can't be written in query expressions though... for example, anything using the Select overload which provides the index as well:

var foo = bar.Select((value, index) => new { value, index });



......当然,所有这些都不会被查询表达式在所有支持的许多运营商(首先等)。

在最低限度的查询会使用的SelectMany 第二子句,选择子句(引进新的透明的标识符),其中,其中,子句和选择选择条款。

The "minimum" query would use SelectMany for the second from clause, Select for the let clause (introducing a new transparent identifier), Where for the where clause, and Select for the select clause.

这篇关于LINQ查询语法和推广方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆