问题描述
有没有一种工具,方法或解决方案,将下面的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的COM prehension查询语法的方法语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!