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

前端 未结 4 1485
既然无缘
既然无缘 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:47

    Internally, the compiler will translate the query syntax into the more explicit lambda syntax. There is no inherent performance gain for either style and the generated code for most scenarios is almost identical to what people type out by hand.

    The main difference is that with the lambda syntax you can chain in any extension method operating off and returning and IEnumerable. With the query syntax, you are limited to the particular extension methods explicitly supported by the language (varies between language)

    Really using or not using the query syntax is really a matter of personal preference.

提交回复
热议问题