Standard Query Operators
[ 208 ]
public static IEnumerable
SkipWhile
(
IEnumerable source,
Func predicate
)
Following is the declaration, similar to the above declaration but the integer used in
the predicate function is the element index, in the sequence.
public static IEnumerable SkipWhile
(
IEnumerable source,
Func predicate
)
The following code skips the first five elements and then retrieves the remaining
elements in the sequences that are greater than five.
int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var lastFive = numbers.SkipWhile(num => num >5);
foreach (int num in lastFive)
Console.WriteLine(num.ToString());
ArgumentNullException is thrown if the source or the predicate function is null.
TakeWhile
This operator starts enumerating a sequence and takes all the elements while a
specified condition is true, and then stops enumerating the remaining elements in
the sequence. Given below is the syntax for TakeWhile, where the first argument is
the source sequence and the second one is the predicate function to check against the
source elements.
Pages:
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311