Let’s say I have integer variables x and y, and I want an array populated with values x through y. Is there a nice way to do this inline, using C#?
I know I can achieve this using an extension method:
public static int[] ExpandToArray(this int x, int y)
{
var arr = int[y - x + 1];
for (int i = x; i <= y; i++)
{
arr[i-x] = i;
}
return arr;
}
And then use it to write:
x.ExpandToArray(y);
Is there a built-in way (without creating an extension method) in .NET to write something like x.ExpandToArray(y)?
Parameter #1 is start value.
Parameter #2 is count.