So I have a generic list, and an oldIndex and a newIndex value.
I want to move the item at oldIndex, to newIndex.
Simplest way:
list[newIndex] = list[oldIndex];
list.RemoveAt(oldIndex);
EDIT
The question isn't very clear ... Since we don't care where the list[newIndex] item goes I think the simplest way of doing this is as follows (with or without an extension method):
public static void Move(this List list, int oldIndex, int newIndex)
{
T aux = list[newIndex];
list[newIndex] = list[oldIndex];
list[oldIndex] = aux;
}
This solution is the fastest because it doesn't involve list insertions/removals.