Posted in:

The fifth video in my Exploring MoreLINQ series looks at the Scan extension (along with ScanRight and PreScan), which is really great for calculating running totals, or tracking any kind of state all the way through a sequence. You can think of it as being a bit like LINQ's Aggregate method but where you want to be able to examine the values of the accumulator as you work through the sequence.

The "real-world" example I share in the video involves tracking reindeer positions which was one of the puzzles in an Advent of Code challenge. In fact, Scan turned out to be useful in about half a dozen of the Advent of Code challenges I've attempted, so it is a method worth familiarizing yourself with.

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.