比较:LINQ vs LAMBDA表达 [英] Comparison : LINQ vs LAMBDA Expression

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

问题描述

我需要讨论LINQ和Lambda Expression的性能.

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

哪个更好?

推荐答案

我想您在这里谈论LINQ时是指query expression.

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

它们是等效的.编译器将query expression更改为等效的Lambda表达式,然后再对其进行编译,因此生成的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);

请注意,如果您这样编写查询表达式:

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

省略了对Select的最终调用,因为这是多余的.

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

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

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