Last active
June 23, 2016 18:28
-
-
Save pilotgeraldb/483ff82582854f791dae6328655f1e18 to your computer and use it in GitHub Desktop.
allows to 'move' items in an IList object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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