fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. class OrganisationUnit
  8. {
  9. public string ID;
  10. public int Index;
  11. }
  12.  
  13. public static void Main()
  14. {
  15. OrganisationUnit[] units = {
  16. new OrganisationUnit{ID="A",Index=1},new OrganisationUnit{ID="B",Index=2},new OrganisationUnit{ID="C",Index=3},
  17. new OrganisationUnit{ID="D",Index=4},new OrganisationUnit{ID="E",Index=5},new OrganisationUnit{ID="F",Index=6},new OrganisationUnit{ID="G",Index=7}
  18. };
  19.  
  20. var f = units.First(u => u.ID == "F");
  21. int newFIndex = 2;
  22. foreach (OrganisationUnit u in units.Where(u => u.Index >= newFIndex && u.Index < f.Index).ToList())
  23. u.Index++;
  24. f.Index = newFIndex;
  25.  
  26. foreach (OrganisationUnit u in units.OrderBy(uu => uu.Index))
  27. Console.WriteLine(string.Format("ID={0} Index={1}",u.ID,u.Index));
  28. }
  29. }
Success #stdin #stdout 0.05s 38208KB
stdin
Standard input is empty
stdout
ID=A Index=1
ID=F Index=2
ID=B Index=3
ID=C Index=4
ID=D Index=5
ID=E Index=6
ID=G Index=7