Move IList<T> item to top

Found myself in need of moving an item stored in an IList to the top of the stack. Some IList methods like RemoveAt() and Insert() would work however wouldn’t be as efficient with a large data set. Fortunately found a Stack Overflow post which would do the move in a single step. I renamed the extension to MoveToTop and here’s a quick and easy Xamarin Workbook sample.

Output:

Id: 3 Name: Third
Id: 1 Name: First
Id: 2 Name: Second

Hope someone finds this useful. Feel free to share/like etc.

Written by

Principal Software Engineer at Command Health https://github.com/dannycabrera

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store