Sam Sam - 1 year ago 109
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 Source

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

return Enumerable.Range(30, 21).ToArray();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download