开发者

Which is higher in Abstraction Level Linq or Lambda expression

I always prefer lambda expression to perform operations on co开发者_StackOverflow中文版llection. But i can achieve same thing with LINQ which is simpler than Lambda expression. but, I am still confused a bit about which comes at top in Abstraction Level & why?


I suspect by "LINQ" you mean "query expressions":

var query = from x in y
            where x.Foo
            select x.Bar

And I suspect by "lambda expression" you mean calling the extension methods directly:

var query = y.Where(x => x.Foo)
             .Select(x => x.Bar);

Both of these are really LINQ...

Query expressions are at a slightly higher abstraction level I guess, and that there's more work required to get down to the real operations... but not terribly significantly, given that the conversion process is fairly mechanical.


LINQ expressions are translated by the compiler into the corresponding extension methods. Lambda expressions are part of the BCL, whereas LINQ syntax is just syntactic sugar which gets translated by the compiler, it's not part of the emitted IL.


I'm guessing your question is actually about the difference between Linq in query syntax (from car in carList select car.Brand) and method syntax (carList.Select(car => car.Brand))? In that case, it is easily answered: Linq's query syntax is only syntactic sugar, and will be translated into method calls. As such, they are pretty much identical as far as abstraction level goes. Query syntax just looks more comprehensible to the average human.

Menno

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜