// Query #1.
List
// The query variable can also be implicitly typed by using var
IEnumerable
from num in numbers
where num < 3 || num > 7
select num;
// Query #2.
IEnumerable
from num in numbers
where num < 3 || num > 7
orderby num ascending
select num;
// Query #3.
string[] groupingQuery = { "carrots", "cabbage", "broccoli", "beans", "barley" };
IEnumerable<IGrouping
from item in groupingQuery
group item by item[0];
Note that the type of the queries is IEnumerable<(Of <(T>)>). All of these queries could be written using var as shown in the following example:
var query = from num in numbers...
In each previous example, the queries do not actually execute until you iterate over the query variable in a foreach statement.
No comments:
Post a Comment