我有一个数组如下:
School[] _schools = new School[MxNr];
并且对象School
具有属性`Room []。
我已将foo.class
的房间数组中的所有房间插入如下:
Rooms[] rooms = new Rooms[NrOfRooms];
int temp2 = 0;
foreach (School school in _schools) {
foreach (Rooms room in school.Rooms) {
room[temp2++] = room;
}
}
现在我更新房间:
Room[0] = new Room(SomeVal);
但是当我遍历学校数组时,我可以看到房间没有更新,仍然保留旧值。
编辑:
public class School {
public School(string schoolStr, bool IsFirstSchool = false, bool IsLastSchool = false) {
int nrOfRooms = IsFirstSchool || IsLastSchool ? 1 : 2;
Rooms = new Room[nrOfRooms];
Rooms[0] = new Room(someVal);
Rooms[1] = new Room(someVal);
}
public Room[] Rooms { get; set; }
}
我想知道为什么以及如何在c#中解决这个问题。