Link to home
Start Free TrialLog in
Avatar of Kobi55
Kobi55

asked on

ReDim Preserve(vb6) in C#

Hi

how can i do like "vb6"   (ReDim PreserveArray)   but  in  C#
not with ArrayList

regards
Avatar of tzxie2000
tzxie2000
Flag of China image

If you just want to change the array length please test code below

int [] a=int[16];
a=int[32];
a[31]=12;

you can create a new int array and assigned to a.
you can change int to other types

Avatar of a_goat
a_goat

VB's ReDim Preserve compiles to the following

int[] a = int[16];

// This is the redim stuff
int[] b = int[16];
for (int I = 0; I < a.Length && I < b.Length; I++)
    b[I] = a[I];
Sorry, to add to that...


int[] a = int[16];

// This is the redim stuff
int[] b = int[16];
for (int I = 0; I < a.Length && I < b.Length; I++)
    b[I] = a[I];

a = b;
SOLUTION
Avatar of a_goat
a_goat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial