Query Syntax vs. Query Methods
As the preceding section has explained, C# has two ways of creating queries: the query
syntax and the query methods. What is interesting, and not readily apparent by simply
looking at a program’s source code, is that the two approaches are more closely related than
you might at first assume. The reason is that the query syntax is compiled into calls to the
query methods. Thus, when you write something like
where x < 10
the compiler translates it into
Where(x => x < 10)
Therefore, the two approaches to creating a query ultimately lead to the same place.
Given that the two approaches are ultimately equivalent, the following question
naturally arises: Which approach is best for a C# program? The answer: In general, you
will want to use the query syntax. It is fully integrated into the C# language, supported by
keywords and syntax, and is cleaner.
Do'stlaringiz bilan baham: |