c# - 比较 : LINQ vs LAMBDA Expression

标签 c# 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/

相关文章:

java - 列表到 Java 8 中的 BiMap

c# - UWP Ctrl+F 实现

c# - 如何在 C# 中嵌入 VBS 并运行它?

c# - 如何找出哪个进程正在使用 .NET 锁定文件?

c# - 在.Net中使用Linq解析没有根元素的xml元素

c# - {"LINQ to Entities does not recognize the method ' bool IsLetter(字符 )' method, and this method cannot be translated into a store expression."}

linq - NHibernate IQueryable 似乎没有延迟执行

c++ - 不能使用显式类型的 lambda

c# - 如何向初始化的表达式树添加新成员?

c# - 如何等待 PuppeteerSharp 中的异步函数评估