using System; using System.Linq; using System.Collections.Generic; public class Test { public class BtnCountViews { public int DayOfYear { get; set; } public int BtnCount { get; set; } public int Views { get; set; } } public static void Main() { var rnd = new Random(); List items = Enumerable .Range(1, 10) .Select(_ => new BtnCountViews {DayOfYear = rnd.Next(20, 200)}) .ToList(); items.Sort((x, y) => x.DayOfYear.CompareTo(y.DayOfYear)); Console.WriteLine("Before: {0}", string.Join(", ", items.Select(x => x.DayOfYear))); int i = items.Count-1; while (i > 0) { if (items[i].DayOfYear == items[i-1].DayOfYear+1) { i--; } else { items.Insert(i, new BtnCountViews { DayOfYear = items[i].DayOfYear-1 }); } } Console.WriteLine("After: {0}", string.Join(", ", items.Select(x => x.DayOfYear))); } }