I have a list of items and a "selected" list (a subset of the full list). I want to implement a function that moves the sub list items to the bottom of the full list.
For instance, if I have selected the elements 2,4, & 6 from the list 0,1,2,3,4,5,6,7,8,9 I want this function to have the end result 0,1,3,5,7,8,9,2,4,6
Currently, I'm trying to use something like this, but I'm not sure how to define moveTo
:
public object MoveLoopToBottom()
{
if (selectedLoops.Count < 1)
return null;
foreach (ProfilerLoop selected in selectedLoops)
{
int moveFrom = ClonedLoops.IndexOf(selected);
int moveTo = ;
ClonedLoops.Move(moveFrom, moveTo);
}
return null;
}
I consulted this for how List.Move
works: Generic List - moving an item within the list but it appears that it can't "move to end of list". List.Move
can (at most) move to the "second-to-last" position (trying to move to the end of the list throws "OutOfRange Exception").
Instead of List.Move
, I tried doing List.Remove
then List.Add
(or List.Add
then List.RemoveAt
) but calling List.Remove
gives me problems with my foreach loop iterations (where List.Move
does not).
Any suggestions?