如果有一個陣列,例如:如何從一個數組中獲取一個值用於另一個類中?
//....
int[] anArray;
anArray = new int[3];
anArray[0] = new otherClassWConst(x, y , z);
anArray[1] = new otherClassWConst(x, y , z);
anArray[2] = new otherClassWConst(x, y , z);
//....
隨着x和y和z都存在不同的值的與所述其他的x,y和z的從所述陣列中的其他對象的值。 (這有意義嗎?就像anArray [0]中的x的值與anArray [2]中的值不同一樣)。 注意:有另一個類的構造函數需要這些參數,我不確定這是否重要
我如何在不同的類中獲取其中一個參數的值(例如, y的值)在每個數組值中。如果有,我可以得到Y的所有三個值的方法,以便我可以將它們一起添加到另一個類中?
例如
//code attaining only the y values of the array
overallValueOfY = Y + Y + Y; // or something of that nature
//life continues over here.
請告訴我,如果有任何不明白,我那麼努力解釋。感謝您的考慮。
顯示你的班級結構。 –