有沒有一種簡單的方法,也是最重要的,更優化做打鳥代碼:複製每個列表項另一個列表項attribut
class Chair{
int numberOfLegs=4;
}
class House{
Chair chair;
String name="My Home";
}
// add chairs to each house
IList<Chair> chairs = new List<Chair>(10); // let us imagine that we have 10 different chairs...
// Code to replace:
IList<House> houses = new List<House>(chairs.Count());
for (int i = 0; i < houses.Count(); i++){
houses[i].chair = chairs[i]
}
「代碼替換」不會成功,因爲列表最初是空的。 – usr
該代碼僅供您瞭解該問題。想象一下,我們有10把椅子的清單:P – jbatista