Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

Comprehension Syntax

Comprehension Syntax

We have already met the comprehension syntax at the beginning of Section XV. This is an SQL-like syntax that realizes an easier-to-use, more intuitive access to the major extension methods in the System.Linq.Enumerable class (especially for a programmer who is familiar with SQL).

A comprehension query expression must always start with a from clause. A from clause declares an (iteration) variable, which one can use for traversing through the collection specified after the in keyword. The (almost) complete syntax (Albahari & Albahari, 2008) is depicted in Figure 1. A from clause can be followed by any number of orderby (Section Hiba! A hivatkozási forrás nem található.), where (Section Hiba! A hivatkozási forrás nem található.) or join (Section Hiba! A hivatkozási forrás nem található.) clauses. At the end of a query, one must write either a select (Section Hiba! A hivatkozási forrás nem található.) or a group clause (Section Hiba! A hivatkozási forrás nem található.). By using into (Section Hiba! A hivatkozási forrás nem található.), the result of a query can be saved into a variable, which can then be used to further continue the query with orderby/where/join clauses.

XV.1. Comprehesion syntax (Albahari & Albahari, 2008)

In the subsequent sections, we will show examples how to use comprehension syntax.