Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a 2d Array and i need to increase the first dimension. Is this possible? I cant seem to get it to do it. I dont really want to have to change all of the code but if there isnt another way... i suppose i will have to.

 

 

Ta very much.

 

Chris

Chris
  • Leaders
Posted

Would switching your dimensional order work?

i.e.

(dimension1, dimension2) -> (dimension2, dimension1)?

 

Other than that, the following works in VB6 and I'd assume that it works in .NET.

Public Structure MyArray
 Public Elements() As Integer
End Structure
Public DualResizeArray() As Integer

And then, you can resize each dynamic array with Redim.

:)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Depends on if you're trying to preserve your data, in which case "redim preserve" won't do the trick. Otherwise, you'll have to make a new array and copy the original array members into the new array, which "preserve" is doing behind the scenes anyhow (creating a new array).

 

Here's from MSDN:

ReDim releases the existing array and creates a new array with the same rank. The elements of the new array are initialized to the default value for their data type unless you specify Preserve.

 

If you include the Preserve keyword, Visual Basic copies the elements from the existing array to the new array. When you use Preserve, you can resize only the last dimension of the array, and for every other dimension you must specify the same size it already has in the existing array.

 

For example, if your array has only one dimension, you can resize that dimension and still preserve the contents of the array, because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension if you use Preserve.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...