Create c# int[] with value as 0,1,2,3... length

arrays, c#

Solution

You can avail the functionality of IEnumerable.

int[] arr = Enumerable.Range(0, X+1).ToArray();

This will create a IEnumerable List for you and `.ToArray()` will satisfy your int array need.

So for X=9 in your case it would generate the array for `[0,1,2,3,4,5,6,7,8,9]` (as you need)

Problem

I like to create an `int[]` with length `X` and value it with [0,1,2....X] e.g. `public int[] CreateAA(int X){}` `int[] AA = CreateAA(9) => [0,1,2,3,4,5,6,7,8,9]` is there any easy method? Or have to loop and init value

Original source

Related problems