繁体   English   中英

为什么每个的左侧尺寸不等于右侧?

[英]Why the left side size in for each is not equal to the right side?

for-each声明的大小总是小于数组的大小。为什么?

int[][][] c = {{{1,2,3}}};
for(int [][] z : c )
    //code

c 是一个 3D 数组,所以 z 应该是,对吗? 喜欢:

int[][][] c = {{{1,2,3}}};
for (int[][][] z : c) // which is syntactically wrong
    //code

先感谢您。

我从评论和以下答案中理解的答案: for-each内部的声明

在 3D 数组中for-each将每个 2D 数组视为一个元素,

在二维数组中for-each将每个一维数组视为一个元素,依此类推。

在一维数组中,它直接将数组的元素作为元素。

将该构造读作for-each循环。 在这种情况下,对于int[][]中的每个int[][] int[][][] 另一个例子, for-each int in an int[]

int[] arr = {1,2,3};
for (int i : arr) {
    System.out.println(i);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM