有没有一种简单的方法,最重要的是,更优化的代码:
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]
}