tags:

views:

201

answers:

3

I need to generate a list of sequential numbers. I know Ruby you can do 1..10 or PHP you can do range(1, 10). Anything like that in .Net already, or do I have to write it? Thanks.

A: 

Would this work for you?

public List<int> Range(int start, int finish)
{
  List<int> retList = new List<int>();
  for(int i = start; i <= finish; i++)
  {
     retList.Add(i);
  }
  return retList;
}
scottm
I actually wrote a method exactly like this before I saw you could use Enumerable.Range. Thanks.
Kevin
Yeah, that's new to me also. I really need to get a 3.0 book, but I think I'm just going to wait until 4.0
scottm
+5  A: 

In C# (with .NET 3.0 or higher) this should do the job:

IEnumerable<int> myRange = Enumerable.Range(1, 10);
+1  A: 

You can use Enumerable.Range()

CMS