Moving places with a room that used to be higher should do this:
int roomIndex = parentBuilding.Rooms.IndexOf(room); if (roomIndex == 0) { return; } var wasAbove = parentBuilding.Rooms[roomIndex - 1]; parentBuilding.Rooms[roomIndex - 1] = room; parentBuilding.Rooms[roomIndex] = wasAbove;
However, I'm not sure if this is the best object model for the situation; it is not clear that the order of the numbers in the list plays a role, and it is also unclear how you can "raise" a room - what does it mean?
It might be better to have a RoomPlacement class that combines the room and enough information to find it and work with it.
source share