Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a dimension to a multidimensional array in c#

I have a multidimensional array

byte[,] matrix;

and i want copy in a 3 dimension array

byte[,,] 3dplan; 

in this way

3dplan[,,0]=matrix

What is the fastest way to accomplish this task in c#?

like image 240
Alfredo Avatar asked May 10 '11 15:05

Alfredo


People also ask

Does C allow multi-dimensional array?

Multidimensional Arrays in C / C++ A multi-dimensional array can be termed as an array of arrays that stores homogeneous data in tabular form. Data in multidimensional arrays are stored in row-major order.


1 Answers

You need to manually copy the elements in a nested loop; there is no faster way.

If you switch to a jagged array (byte[,][] or byte[][][]), you can insert the smaller array as-is into a slot in the larger array (although they will both refer to the same array instance and will pick up changes)

like image 193
SLaks Avatar answered Oct 30 '22 01:10

SLaks