PHP range() function in .NET?
Question
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.
Solution
In C# (with .NET 3.0 or higher) this should do the job:
IEnumerable<int> myRange = Enumerable.Range(1, 10);
OTHER TIPS
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;
}
You can use Enumerable.Range()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow