Eri*_*ert 19
将lambda添加到语言中的理由是两件事.
(1)它们使查询理解的语法转换成为可能.当你说
from customer in customers
where customer.City == "London"
select customer
Run Code Online (Sandbox Code Playgroud)
那变成了
customers.Where(customer=>customer.City == "London")
Run Code Online (Sandbox Code Playgroud)
(2)它们可以转换为表达式树,从而使LINQ-to-SQL,LINQ-to-Entities等成为可能.也就是说,他们可以代表都做它们的语义的能力,并检查其结构的能力.