开发者

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 }


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜