Question

I want to create a 2D jagged array (as previous so answers claims is faster on dot net than multidimensional one).

I want to do something like

Int [][] myarr = new int [2][3]; 

But C# doesn't seem to support this so I did use a for loop for the 2nd dimension instantiation. Yet if I want to fastly reset I cant use memset equivalent as each new in the loop initiate the array in a possible different and not continouse place.

Is there a faster way to init and reset a fixed width jagged array ?

Was it helpful?

Solution

You can use LINQ and Enumerable.Range method, but internally there is still a loop performed:

int[][] myarr = Enumerable.Range(0, 2).Select(x => new int[3]).ToArray();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top