When to use lambda expressions instead of a Where clause in LINQ

前端 未结 4 1437
既然无缘
既然无缘 2021-02-06 11:18

I\'ve been really digging into LINQ, and I\'m trying to hash out this lambda expression business. I\'m just not seeing the benefit of some of the nuances of the syntax. Primari

4条回答
  •  别那么骄傲
    2021-02-06 11:45

    Take a look at this article: LINQ Query Syntax versus Method Syntax :

    In general, we recommend query syntax because it is usually simpler and more readable; however there is no semantic difference between method syntax and query syntax. In addition, some queries, such as those that retrieve the number of elements that match a specified condition, or that retrieve the element that has the maximum value in a source sequence, can only be expressed as method calls. The reference documentation for the standard query operators in the System.Linq namespace generally uses method syntax. Therefore, even when getting started writing LINQ queries, it is useful to be familiar with how to use method syntax in queries and in query expressions themselves.

    And also this question: LINQ: Dot Notation vs Query Expression

提交回复
热议问题