I am relatively new to c# and am making a 2D physics engine as a fun project to learn the language and the .NET environment.
I am making a form that can be used to modify the number of objects. Unfortunately, I cannot find a way to change the length of the array passed to the form via its constructor.
I suppose "ref" would work except that the length is actually modified in another method besides the constructor.
Some combination of "unsafe" and "fixed" might also have worked if they could be made to have scope outside the constructor method of this form's class.
I want to do something like the pseudo code below:
//When appropriate menu item clicked, create an instance of the "new ball creation" form:
AddBallClass NewBallWindow = new AddBallClass(ref BallArray, MouseClickPos.X,MouseClickPos.Y);
NewBallWindow .Show();
//code found in the "AddBallClass" form:
public class AddBallClass: Form{
...
private Ball[] *PointerToBallArray;
private int PosX,PosY,length;
private Ball[] NewBalls;
...
public AddBallClass(ref Ball[] Balls, int x, int y){
PointerToBallArray=&Balls[];
PosX=x;
PosY=y;
length=Balls.Length();
NewBalls = new Ball[length+1];
Balls.Copy(NewBalls);
}
...
private void OKbutton_Click(object sender, EventArgs e)
{
*PointerToBallArray = new Ball[length+1];//increasing the size of the original array, to make room for the new ball
NewBalls.Copy(*PointerToBallArray);//copy the new ball list data to the original.
}
}
Thanks,
Dustin