redim arrayx?????

  • Thread starter Thread starter jamie
  • Start date Start date
J

jamie

As you might have guessed,
I am trying to switch from
vb to c#, but I am having
a little difficulty.

How would you resize an array in
c# ? Is there a "redim preserve"
as well??

An example would go a long way.
Thanks jamie
 
You have to do it yourself, manually. You have to create a new array
and copy the elements into it:

int[] myArray = new int[5];
int[] temp = new int[10];
for (int i = 0; i < myArray.Length; i++)
{
temp = myArray;
}
myArray = temp;

That's why it's much more common in C# to use ArrayList and convert to
an array only when you really need an array (for example to pass to
some method that requires an array).
 
Use an ArrayList. It will resize itself as you need it to. Internally, it
creates a copy of the array with the new size, and copies the existing data
to the copy, then renames the copy - which is exactly what a redim preserve
in VB does internally.

HTH

Dale Preston
MCAD, MCDBA, MCSE
 
I think the recipe is exactly
what I need to do. I knew I could
do it that way, I was just hoping
that I wouldnt have to for clarity
sake.

Thanks.
 
Back
Top