Common use of the Array extension:

To create a single dimension integer array with 10 elements use:

 int[] arr = Enumerable.Range(1, 10).ToArray(); 
** this extension overlaps the standard Linq extension.

To create a two dimension integer array with 24 elements (3X8) use:

int[,] arr2D = Enumerable.Range(1, 24).ToArray(3, 8); 


Rotate the array (90 degrees):

int[,] arr2Dr90 = arr2D.Rotate(90)


The following creates a three dimension integer array with 24 elements (2X3X4):

int[, ,] arr3D = Enumerable.Range(1, 24).ToArray(2, 3, 4); 


The following rotates the three dimension integer array on its Z axis by 90 degrees resulting in a 2X4X3 array:

int[, ,] arr3Dr90 = arr3D.Rotate(RotateAxis.RotateZ, 90); 


When rotating 3D and 4D arrays the axis must be supplied.

All rotations a clock-wise valid values for 2D, 3D are 0,90,180 and 270 values of 360 and higher will case a full rotation: 450 will have the same effect as 90.

Negative values are acceptable and cause the rotation to be counter clock.

Rotating a 3D array on a single axis four time - 90 degrees each - will bring the array to its starting point.

4D arrays rotate on a 540 degrees space and require 6 rotations of 90 degrees - on a single axis - to return to the starting point.

Last edited May 2, 2012 at 8:13 PM by AmirLiberman, version 6


No comments yet.