LINQ查询语法和推广方法 [英] Linq query syntax and extension methods
问题描述
我通常喜欢的扩展方法,因为我觉得他们更容易阅读,但艾尔诺看到答案的这个问题我想知道最小的查询将如何看待与仅使用扩展方法?
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屋!