In F#, you can generate a set of numbers, just by saying [1..100].
I want to do something similar in C#. This is what I have come up with so far:
public static int[] To(this int start, int end)
{
var result = new List<int>();
for(int i = start; i <= end; i++)
result.Add(i);
return result.ToArray();
}
By doing this, I can now create a set by saying 1.To(100)
Unfortunately, this is not nearly as readable as [1..100]. Has anyone come up with a better way to do this in C#? Is it more readable if it is lowercase? 1.to(100), for instance? Or, is "To" a bad word? Is something like 1.Through(100) more readable?
Just looking for some thoughts. Has anyone else come up with a more elegant solution?
EDIT: After reading the responses, I have re-written my To method using the range:
public static int[] To(this int start, int end)
{
return Enumerable.Range(start, end - start + 1).ToArray();
}
I am still looking for thoughts on the readability of 1.To(100)