From the course: .NET Essentials: Working with LINQ

Unlock this course with a free trial

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

Skip and Take methods

Skip and Take methods

- [Instructor] By using the Take and Skip extension methods, we can get a subset of the sequence. Take, get a consecutive subset of the sequence and Skip a consecutive subset of the sequence. So I'm starting out with, 50 items in my numbers list To here I'm calling Take five. So that will return, the first five items in the sequence. When I call Skip, it Skips to this position, position 46. So when I call that way and I get the rest of the list, it's also a way of saying I'm getting the last four items in the list, 47 through 50. You can also use calculations like I'm doing here, I'm getting the count of the items in the sequence and then subtracting 12. So that returns the last 12 items. And of course you can combine these like this Skip 11, Take three so when I'm doing that, I'm starting at the 12th position and getting 12, 13, and 14 and getting those three items are here I'm skipping two, starting at the third position…

Contents