Putting an array inside of an array.
Not sure if this is the appropriate forum, but it sounds like something a graphics programmer might have had to deal with before.
Let's say I have a 2D array of boolean, representing the surface of a monochrome screen. Let's say I have another 2D Array, representing an object to place in that screen, and want to put it in a specific place inside the first array. i.e,
00000000
00000000
00000000
00000000
00000000
00000000
is my first array
and
11
11
is my second.
What would be a good way (in psuedocode) to do something like this
InsertArray(4,3)
That would result in the original array looking like
00000000
00000000
00011000
00011000
00000000
00000000
Any suggestions? Obviously the arrays are much bigger, but the idea should be the same regardless..
Bill
Re: Putting an array inside of an array.
I found a way to do it if I know beforehand the size of the array being placed into the first array. Is there a way to get the dimensions of a 2D array? For example, if I have a 4x4 array, and call Array.Length, I will get 16. Since it won't always be a square, is there a way to find out how the 2D array is structured?
Bill
Re: Putting an array inside of an array.
In what language? If you're talking vb6, you would get the first two dimensions using ubound(array,1) and ubound(array,2).
Re: Putting an array inside of an array.
Should have specified... This is C#, but There should be an equivalent to ubound there somewhere.. Thanks.
Bill
Re: Putting an array inside of an array.
.NET uses Upperbound and LowerBound I think. Should be something like:
chem
Re: Putting an array inside of an array.
Code:
myArray.GetUpperBound(0); // first dimension
myArray.GetUpperBound(1); // second dimension
Re: Putting an array inside of an array.
So what are you doing?
If you have the main array (mainA() and the new array newA()), and you have a function Insert( left,top,newA()), then you could:
Loop through dimension 0
Loop through dimension 1
mainA(top plus outer loop, left plus inner loop) = newA(outer loop, inner loop)
That is roughly what could be done. Of course, you would only need to loop through a range defined by top+size of newA() dimension 0, and left+ size of newA() dimension 1.