Skip to content

Instantly share code, notes, and snippets.

@pilotgeraldb
Last active June 23, 2016 18:28
Show Gist options
  • Select an option

  • Save pilotgeraldb/483ff82582854f791dae6328655f1e18 to your computer and use it in GitHub Desktop.

Select an option

Save pilotgeraldb/483ff82582854f791dae6328655f1e18 to your computer and use it in GitHub Desktop.
allows to 'move' items in an IList object
public static void Move<T>(this IList<T> list, int oldIndex, int newIndex)
{
var item = list[oldIndex];
list.RemoveAt(oldIndex);
if (newIndex > oldIndex)
{
newIndex--;
}
// the actual index could have shifted due to the removal
list.Insert(newIndex, item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment