CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jean-Paul S. Boodhoo

Develop With Passion

Amendment to DNRTV Episode Part 3

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.


Published May 25 2007, 12:05 PM by bitwisejp
Filed under: ,

Check out Devlicio.us!