-1

我希望能够在 for 循环中访问对象,如下所示:

for (int i=0; i<5: i++)
{ object[i].doSomething(); }

然而,这部分的语法object[i]让我无法理解。

4

1 回答 1

2
for (        // loop
int i = 0;   // initialize the variable i before starting to iterate
i < 5;       // perform the block below while i < 5
i ++ )       // increment i after performing the block below
{                      // start of block to execute in each iteration of the for-loop
    object[i]          // the i-th element of the array object
    .doSomthing();     // call this method on ^^ 
}                      // end block

好的参考资料:

于 2012-04-29T02:20:29.720 回答