C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Differences in design in MiscUtil

Chapter 6: Implementing iterators the easy way: 6.3.2

Created: 2/24/2008
Last updated: 2/24/2008

After a couple of iterations of design, the Range class in MiscUtil no longer supports iteration over itself. Instead, you create a RangeIterator which has the concept of a range, which end to start at, and the step to take (implemented with a delegate).

A Range itself then only has a start, an end, a Comparer , and inclusive/exclusive flags for each end. It's a mathematical interval (which can be closed, open, or half-open at either end). Separating the concerns of iteration and the range itself is much more satisfying in the long run, and also makes immutability somewhat easier to achieve.