比较:LINQ VS LAMBDA前pression [英] Comparision : LINQ vs LAMBDA Expression

查看:172
本文介绍了比较:LINQ VS LAMBDA前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要关于LINQ和Lambda前pression的性能进行了讨论。

i need a discussion regarding the Performance of LINQ and Lambda Expression.

哪个更好?

推荐答案

我猜你的意思是查询前pression 这里谈论LINQ的时候。

I guess you mean query expression when talking about LINQ here.

它们是等价的。编译器改变了查询前pression 成等价的lambda前pression编译它之前,因此产生IL是完全一样的。

They are equivalent. The compiler changes the query expression into the equivalent Lambda expression before compiling it, so the generated IL is exactly the same.

示例

var result = select s from intarray
             where s < 5
             select s + 1;

是完全相同

var result = intarray.Where( s => s < 5).Select( s => s+1);

请注意,如果你编写查询前pression是这样的:

Note that if you write the query expression like this:

var result = select s from intarray
             where s < 5
             select s;

它转换为:

var result = intarray.Where( s => s < 5);

被省略选择最终调用,因为它是多余的。

The final call to Select is omitted because it's redundant.

这篇关于比较:LINQ VS LAMBDA前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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