从数组更新obj的值(初学者)

时间:2015-08-23 14:58:53

标签: c# .net

我有一个数组如下:

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#中解决这个问题。

0 个答案:

没有答案