From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Conditional Skip and Take methods

Conditional Skip and Take methods - .NET Tutorial

From the course: .NET Essentials: Working with LINQ

Conditional Skip and Take methods

- There is another version of take and skip called "TakeWhile" and "SkipWhile". And these both take a predicate function, and you see what it does. It returns elements from a sequence, as long as the specified condition is true, and then skips the rest of the elements. Or what SkipWhile. It skips all the items, as long as the specified condition is true, and then returns the remaining elements. So look at my list of data. I've got these numbers, and then here's the condition I'm looking for. Less than 100. So at this point, if I do take, it's going to go up to this point and stop, because 201 is greater than 100. And if I'm using SkipWhile, it's going to skip up to this point and take the rest of these numbers. Let's make this more interesting, and change this to 250 for the second one. Just so we can see the difference. For the first results, it takes until it gets to 65. That's good, but 201, it doesn't meet the…

Contents