Scott Klein
"Professional LINQ"
GetTable
();
string name = "Kleinerman"
var query = from c in contact
select c.LastName;
listBox1.Items.Add(query.Contains(name));
85
Part I: Introduction to Project LINQ
Partitioning Operators
Partitioning is the act of dividing a single input sequence into two or more sections or sequences without
rearranging the incoming elements, then returning one of the newly formed sections.
The partitioning operators??”skip, skipwhile, Take, and TakeWhile??”are discussed in this section.
Skip
The Skip operator skips elements up to a specified location within a sequence. In other words, it bypasses
the specified number of elements and returns the remaining elements.
The following example defines a random set of numbers, orders them in ascending order, then uses the
Skip operator to skip the first four and return the remaining.
Int[] randomNumbers = {86, 2, 77, 94, 100, 65, 5, 22, 70};
IEnumerable skipLowerFour =
randomNumbers.OrderBy(num => num).Skip(4);
foreach (int number in skipLowerFour)
listbox1.Items.Add(number);
When this query is run, the following numbers are returned:
70
77
86
94
100
This example could also be written using query syntax as follows:
IEnumerable skipLowerFour =
(from n in randomNumbers
order by n
select n).
Pages:
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170