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);
}
}