using System.Collections.Generic;
public static void Main()
var list = new List<DateTime>()
new DateTime(2023, 05, 02),
new DateTime(2023, 05, 03),
new DateTime(2023, 05, 04),
new DateTime(2023, 05, 10),
new DateTime(2023, 05, 11),
new DateTime(2023, 05, 20),
var results = list.GroupUp((a, b) => a.AddDays(1) >= b);
public static class Extensions
public static IEnumerable<IEnumerable<T>> GroupUp<T>(this List<T> source, Func<T, T, bool> isSameGroupFunc)
for (var start = 0; start < source.Count; start++)
while (end + 1 < source.Count)
if (!isSameGroupFunc(source[end], source[end + 1]))
yield return SkipTake(source, start, end + 1);
private static IEnumerable<T> SkipTake<T>(List<T> source, int start, int count)
for (var i = start; i < count; i++)