Sam Sam - 27 days ago 12
C# Question

Initialize an array of int with a range of numbers

I want to initialize an array of int and populate it with a range of numbers:

return new int[].Populate(30,50);


So then I would have an array with 30, 31, 32, 33... - 50

Answer

You can use Enumerable.Range() to e.g. return an array of 21 integers starting at 30:

return Enumerable.Range(30, 21).ToArray();
Comments