0 Comments Posted in:

The sixth video in my Exploring MoreLINQ series looks at the TakeLast, TakeUntil and TakeEvery extension methods, which add to the capabilities of the standard LINQ Take and TakeWhile methods.

TakeLast allows you to take items from the end of a sequence, TakeEvery allows you to sample items from a sequence (e.g. take every third item), and TakeUntil is subtly different from LINQ's TakeWhile in that it includes the first item that matches the predicate. This simple example highlights the difference between the two:

"AAABBB".TakeWhile(c => c == 'A') // returns A,A,A
"AAABBB".TakeUntil(c => c != 'A') // returns A,A,A,B

You can find all videos in this series here.

Want to learn more about LINQ? Be sure to check out my Pluralsight course More Effective LINQ. I'm also speaking on LINQ at Techorama Netherlands 2018 on 3rd October, so I'd love to see you there if you can make it.
Vote on HN