Exploring MoreLINQ Part 6 - Taking
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 LINQ Best Practices.