Shadi Philip
Shadi Philip

Reputation: 1

Initiallizing an Array of Objects

I am initializing and array of objects, i need something like this:

Greyhound[1].StartingPosition = pictureBox1.Location;
Greyhound[2].StartingPosition = pictureBox2.Location; 

and so on.. but I need to make it by a loop

for ( ......... ) 
      { Greyhound[i].StartingPosition = ????????? // what should go here }

Upvotes: 0

Views: 102

Answers (1)

Jay
Jay

Reputation: 1356

If this is C# then something like this should work:

int max = 5;
for(int i = 1; i < max; i++) {
   Greyhound[i].StartingPosition =  this.Controls.Find("pictureBox" + i.ToString(), true)[0].Location;
}

Upvotes: 1

Related Questions