Hooked on LINQ

Hooked on LINQ - Developers' Wiki
for .NET Language Integrated Query

Quick Search

Advanced Search »
{TOC}
Namespace:System.Linq
Assembly:System.Core.dll
Extends:IEnumerable<T>

Back to Standard Query Operator Index


Edit

Introduction

The SkipWhile operator skips elements from a sequence while a test is true and then yields the remainder of the sequence.

Edit

Method Signatures

// 1 - Skip elements while a predicate passes, then return all the remaining elements.
public static IEnumerable<TSource> SkipWhile<TSource>(
    this IEnumerable<TSource> source, 
    Func<TSource, bool> predicate)
 
// 2 - Skip elements while a predicate passes, then return all the remaining elements.
// Also provides index position as an argument for use in the predicate function.
public static IEnumerable<TSource> SkipWhile<TSource>(
    this IEnumerable<TSource> source, 
    Func<TSource, int, bool> predicate)



Edit

Exception

Throws an ArgumentNullException if source or predicate is null.


Edit

Pseudo-code

Overload 1
If source is null, throw an ArgumentNullException.
If predicate is null, throw an ArgumentNullException.
Initialize a flag indicating whether the predicate has been passed to false. (call it yielding)
Iterate the source sequence.
If the yielding flag is false.
If predicate(current element) returns false.
set yielding flag to true.
Else (flag is true, an element has failed the predicate).
Return the current element. Resume execution from this point when the next element is requested.

Overload 2
If source is null, throw an ArgumentNullException.
If predicate is null, throw an ArgumentNullException.
Initialize an index value to zero.
Initialize a flag indicating whether the predicate has been passed to false. (call it yielding)
Iterate the source sequence.
If the yielding flag is false.
If predicate(current element, current index value) returns false.
set yielding flag to true.
Else (flag is true, an element has failed the predicate).
Return the current element. Resume execution from this point when the next element is requested.
Increment the index value count by one.

Edit

Loop Count

< 1. Initially, count number of records are enumerated over with no result returned. This operator implements the standard deferred execution iterator pattern. This means, no looping will occur until the result is iterated over.


Edit

Code Samples

TODO: Needs code sample.

If you would like to comment on this page, click on the Discuss button located on the top-right of each page. Feel free to edit any mistakes or omissions you find. If you have an objection or find in-appropriate content then contact the administrator. This website is not affiliated with Microsoft®, all content and opinions are those of the specific author and some advice, solutions and article may contain unintentional errors - please use care. Powered by ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.