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
You can use Enumerable.Range()
to e.g. return an array of 21 integers starting at 30:
return Enumerable.Range(30, 21).ToArray();
Use Enumerable.Range
var array = Enumerable.Range(30, 21).ToArray();
This will result in a sequence of 21 values starting at 30. Simply put, you get your { 30 ... 50 }
array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With