如何使用 Lambda 将 LINQ Comprehension 查询语法转换为方法语法 [英] How to Convert LINQ Comprehension Query Syntax to Method Syntax using Lambda
问题描述
是否有工具、流程或解决方案可以将以下 LINQ 查询语法转换为使用 Lambda 的方法语法(点表示法)?我希望解决方案将以下查询语法转换为这样的方法语法.
Is there a tool, process or a solution that will convert the following LINQ Query Syntax to Method Syntax with Lambdas (dot notation)? I would expect the solution to convert the following Query Syntax to a Method Syntax such as this.
var filteredEmployees =
from employee in allEmployees
where employee.DepartmentID < 4 && employee.EmployeeID < 10
orderby employee.DepartmentID descending,
employee.LastName descending
select employee;
以下内容
var filteredEmployees2 = allEmployees.Where(employee => ((employee.DepartmentID < 4) && (employee.EmployeeID < 10)))
.OrderByDescending(employee => employee.DepartmentID)
.ThenByDescending(employee => employee.LastName);
我想用它来更好地学习方法语法.
I'm would like to use this to learn Method Syntax better.
推荐答案
LINQPad 是一个很好的工具你需要.我从他们的网站窃取"了以下屏幕截图,以更好地说明它是如何工作的.如果您使用 linq 语法编写查询,则可以单击以红色突出显示的按钮以查看等效的 lambda 语法:
LINQPad is a good tool for what you need. I "stole" the following screenshot from their website to better illustrate how it works. If you write a query using linq syntax you can click on the button highlighted in red to see the equivalent lambda syntax:
这篇关于如何使用 Lambda 将 LINQ Comprehension 查询语法转换为方法语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!