REDIM ARRAY

  • Thread starter Thread starter Jose Fernandez
  • Start date Start date
J

Jose Fernandez

Hello friends.

I have a new problem.

I have Ball class which one of its member is an array. The problem is that I
don't know how many elements it's gonna have at the end of the application.
..NET doesn't allow me to create it without elements.
for example

public class Ball
{
int[] BallHistory=new int[xxx]
(.....)

}

xxx means the lenght of the element. But I don't know how many elements will
have by the end of the application.
Is there any way to make it dynamic??
Thanks in advance
Jose
 
Jose said:
Hello friends.

I have a new problem.

I have Ball class which one of its member is an array. The problem is that I
don't know how many elements it's gonna have at the end of the application.
.NET doesn't allow me to create it without elements.
for example

public class Ball
{
int[] BallHistory=new int[xxx]
(.....)

}

xxx means the lenght of the element. But I don't know how many elements will
have by the end of the application.
Is there any way to make it dynamic??
Thanks in advance
Jose
Either use an ArrayList class which allows you to use add/remove
functionality and you can copy it to a "typed" array at the end or you
could do the following

//Warning: Untested Flycode ahead
int[] Temp = new int[BallHistory.Length + 1];
BallHistory.CopyTo(Temp, 0, 0);
BallHistory = Temp;

JB
 
Back
Top