About Me

Training

Develop With Passion® - Developer Bootcamp

Subscribe

Amendment to DNRTV Episode Part 3

Written May 25, 2007 at 11:04 MDT Tagged c sharp and screencasts

After I finished up recording part 3. I realized that I was not showing off as many ReSharper shortcuts as I could have. That will definitely change over the course of the next set of episodes. For the remainder of the series I will be recording the entire series 'sans mouse'. Hopefully this will give people an idea of how productive you can actually be without using the keyboard mouse. As soon as I had finished recording the session I thought to myself 'yikes, I made that list enumerable way more complicated that it should have been'. Instead of this:

public class ListEnumerable<T> : IEnumerable<T>
{
    private IList<T> itemsToEnumerate;


    public ListEnumerable(IList<T> itemsToEnumerate)
    {
        this.itemsToEnumerate = itemsToEnumerate;
    }

    public IEnumerator<T> GetEnumerator()
    {
        return new ListEnumerator<T>(itemsToEnumerate);
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return new ListEnumerator<T>(itemsToEnumerate);
    }
}

I could have simply done this:

public class ListEnumerable<T> : IEnumerable<T>
{
    private IList<T> itemsToEnumerate;


    public ListEnumerable(IList<T> itemsToEnumerate)
    {
        this.itemsToEnumerate = itemsToEnumerate;
    }

    public IEnumerator<T> GetEnumerator()
    {
        return itemsToEnumerate.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return itemsToEnumerate.GetEnumerator();
    }
}

And of course, an even easier way (if you have .Net 2.0) is to just leverage the yield keyword inside of a method returning IEnumerable. Which is how I started off the discussion on iterators.