using System.Collections.Generic;
using System.Text.RegularExpressions;
var items = new List<Person>()
new Person{Id=1,Name="Harry"},
new Person{Id=2,Name="Peter"}
Console.WriteLine(string.Format("Id:{0}, Name:{1}",i.Id,i.Name));
item.Name = "Not Harry anymore";
items.MoveItemToIndex(item,1);
Console.WriteLine(string.Format("Id:{0}, Name:{1}",i.Id,i.Name));
Console.WriteLine("Harry has been moved and updated");
public string Name {get;set;}
public static class IListExtensions
public static void MoveItemToIndex<T>(this IList<T> list, T item, int newIndex)
if (list == null) throw new ArgumentNullException(nameof(list));
if (item == null) throw new ArgumentNullException(nameof(item));
if (newIndex < 0 || newIndex > (list.Count - 1))
throw new Exception($"Unable to update move item because the index {newIndex} is invalid");
list.Insert(newIndex, item);