I am one of many who have a blog about the ruby-esque method. For the extension you can write if using C # 3.0:
public static class IntegerExtensions { public static IEnumerable<int> To(this int first, int last) { for (int i = first; i <= last; i++)
{ yield return i; } } }
Then you can create a list of integers like
List<int> = first.To(last).ToList();
or
List<int> = 1.To(x).ToList();
Samuel Jack Sep 08 '08 at 8:58 2008-09-08 08:58
source share