More Fun with C# Interators:A Counting Iterator

« Previous article:   Next article: »
I'm Back! Blog Home What's inside a foreach() statement

Michael Herman recently discovered a typo in the MSDN docs:
IEnumberable: the integer version of IEnumerable :-)

This reminded me of a method that I’ve been planning on presenting here: A simple Counting iterator. Basically, it appears to be a collection filled with a sequences of numbers. For example, the following code will print the number from 20 to 41 stepping by three:

 foreach(int i in Iter.Count(20,41, 3))

It’s also good to create an actual collection pre-filled with sequence of numbers:

Also, I should point out that the idea behind this came from a C++ iterator that I first saw presented by Andy Koenig.

kick it on</a>

    comments powered by Disqus