SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 161 | Next

Scott Klein

"Professional LINQ"

OrderByDescending(num => num).TakeWhile(num => num > 50);
foreach (int number in takeGreaterThan50)
listbox1.Items.Add(number);
When this query is run, the following numbers are returned:
100
94
86
81
77
70
66
65
55
This example could also be written using query syntax as follows:
IEnumerable takeGreaterThan50 =
(from n in randomNumbers
order by n descending
select n).TakeWhile(num => num > 50);
As an interesting experiment, try modifying the original query as follows and executing it:
IEnumerable takeGreaterThan50 =
randomNumbers.OrderBy(num => num).TakeWhile(num =>
num > 50);
Was anything returned? Why not? As stated earlier, it returns elements based on a specified predicate
function, and continues to take the elements as long as the specified condition is true. If you order the
sequence in ascending order, the first element it finds does not meet the criteria and therefore the query
does not continue.
Putting Query Operators to Work
There was a ton of information in this chapter, so this section provides an example that enables you
to apply many of the operators you??™ve seen and to begin experimenting with the great functionality
provided by the LINQ query operators.


Pages:
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6