<分区>
我需要讨论有关 LINQ 和 Lambda 表达式的性能。
哪个更好?
<分区>
我需要讨论有关 LINQ 和 Lambda 表达式的性能。
哪个更好?
最佳答案
我猜你在这里谈论 LINQ 时是指查询表达式
。
它们是等价的。编译器在编译之前将查询表达式
更改为等效的 Lambda 表达式,因此生成的 IL 完全相同。
示例
var result = select s from intarray
where s < 5
select s + 1;
完全一样
var result = intarray.Where( s => s < 5).Select( s => s+1);
注意如果你这样写查询表达式:
var result = select s from intarray
where s < 5
select s;
转换为:
var result = intarray.Where( s => s < 5);
省略了对 Select 的最终调用,因为它是多余的。
关于c# - 比较 : LINQ vs LAMBDA Expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3914611/