// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; namespace E { public class MainClass { public static List[] FindGroups(List total, DateTime start, int ndays) { int span = (int)((total[total.Count-1])-start).TotalDays+1; List[] res = new List[(span-1)/ndays+1]; for(int i = 0; i < res.Length; i++) { res[i] = total.FindAll(delegate(DateTime dt) { return start.AddDays(i*ndays) <= dt && dt <= start.AddDays(i*ndays+ndays-1); }); } return res; } public static void Main(string[] args) { List lst = new List(); lst.Add(DateTime.Parse("15-06-2006")); lst.Add(DateTime.Parse("16-06-2006")); lst.Add(DateTime.Parse("17-06-2006")); lst.Add(DateTime.Parse("18-06-2006")); lst.Add(DateTime.Parse("21-06-2006")); lst.Add(DateTime.Parse("22-06-2006")); lst.Add(DateTime.Parse("23-06-2006")); lst.Add(DateTime.Parse("25-06-2006")); lst.Add(DateTime.Parse("27-06-2006")); List[] groups = FindGroups(lst, DateTime.Parse("15-06-2006"), 3); foreach(List g in groups) { foreach(DateTime dt in g) { Console.Write(" " + dt); } Console.WriteLine(); } } } }