public class PeriodList : List { public PeriodList ProjectOnto(PeriodList periodList) { List slicePoints = new List(); foreach (Period p in this) { if (!slicePoints.Contains(p.StartDate)) slicePoints.Add(p.StartDate); if (!slicePoints.Contains(p.EndDate)) slicePoints.Add(p.EndDate); } foreach (Period p in periodList) { if (!slicePoints.Contains(p.StartDate)) slicePoints.Add(p.StartDate); if (!slicePoints.Contains(p.EndDate)) slicePoints.Add(p.EndDate); } slicePoints.Sort(); PeriodList results = new PeriodList(); Period current = null; foreach (DateTime i in slicePoints) { Period best = SelectBest(i, periodList); if (current != null) { if (best == null || best != current) { current.EndDate = i; results.Add(current); current = null; } } // no else here if (current == null) { if (best != null) { current = best; // or copy $ or whatever current.StartDate = i; } } } return results; } public Period SelectBest(DateTime time, PeriodList periodList) { Period x = this.Find ( delegate(Period p) { return (p.StartDate <= time && time < p.EndDate); } ) ; if (x != null) return x.Copy(); Period y = periodList.Find ( delegate(Period p) { return (p.StartDate <= time && time < p.EndDate); } ) ; if (y != null) return y.Copy(); else return null; } } }