linq Linq Using Take while And Skip While SkipWhile()

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Skips elements based on a condition until an element does not satisfy the condition. If the first element itself doesn't satisfy the condition, it then skips 0 elements and returns all the elements in the sequence.

Signature of SkipWhile():

Public static IEnumerable <TSource> SkipWhile<TSource>(this IEnumerable <TSource> source,Func<TSource,bool>,predicate);

Another Over Load Signature:

Public static IEnumerable <TSource> SkipWhile<TSource>(this IEnumerable <TSource> source,Func<TSource,int,bool>,predicate);

Example I:

int[] numbers = { 1, 5, 8, 4, 9, 3, 6, 7, 2, 0 };
var SkipFirstFiveElement = numbers.SkipWhile(n => n < 9);

Output:

It Will return Of element 9,3,6,7,2 and 0.

Example II:

int[] numbers = { 4, 5, 8, 1, 9, 3, 6, 7, 2, 0 };
var indexed = numbers.SkipWhile((n, index) => n > index);

Output:

It Will return Of element 1,9,3,6,7,2 and 0.



Got any linq Question?