Когда использовать лямбда-выражения вместо оператора Where в LINQ

Если вы хотите использовать ветку devel или feature, или вы не опубликовали определенный пакет в реестре NPM, или вы не можете этого сделать, потому что это закрытый модуль, вы можете указать на git:// URI вместо номера версии в вашем package.json:

"dependencies": {
   "public": "git://github.com/user/repo.git#ref",
   "private": "git+ssh://git@github.com:user/repo.git#ref"
}

Часть #ref является необязательной, и это может быть ветвь (например, master), тег (например, 0.0.1) или идентификатор частичной или полной фиксации.

6
задан Andreas Grech 28 June 2009 в 13:57
поделиться

3 ответа

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

9
ответ дан 9 December 2019 в 22:38
поделиться

Read this. Your LINQ queries will get turned into Lambda expressions by the compiler at run time.

1
ответ дан 9 December 2019 в 22:38
поделиться

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.

1
ответ дан 9 December 2019 в 22:38
поделиться