是否有可能告诉我List<>
上下移动元素的最佳方式。
例如,我有一个名为 Building 的类,而 Building 有一个 Rooms 对象列表List<Room>
。房间按名称添加到建筑物中,但我使用此结构生成树视图。用户可以选择在建筑物内上下移动房间。
我试图使用.Reverse(index, count)
,但这似乎没有做任何事情:
// can this item actually be moved up (is it at the first position in it's current parent?)
if (moveDirection == MoveDirection.UP)
{
int roomIndex = parentBuilding.Rooms.IndexOf(room);
if (roomIndex == 0)
{
return;
}
else
{
// move this room up.
parentBuilding.Rooms.Reverse(roomIndex, 1);
}
}