Posted in:

The eighteenth video in my exploring MoreLINQ series looks at the GroupAdjacent and Segment extension methods.

These methods are ideal if you ever need to partition a sequence up into chunks of adjacent elements, but those chunks are not all of the same size like they would be if you simply used Batch.

For example, to solve "Longest Sequence" problem in my LINQ challenge #3, you needed to group a sequence of sales per day into sections of days with consecutive sales and days with no sales. It's quite tricky to achieve with regular LINQ operators, but the GroupAdjacent method makes it straightforward.

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.