using System.Collections.Generic;
public static IEnumerable<IEnumerable<int>> GroupConsecutive(this IEnumerable<int> list)
var group = new List<int>();
if (group.Count == 0 || i - group[group.Count - 1] == 1)
if (group.Count >= 2) yield return group;
group = new List<int> { i };
public static void Main(string[] args)
var groups = new[] {2, 4, 7, 8, 9, 5, 6}.GroupConsecutive();
foreach (var g in groups)
Console.WriteLine("group: {0}", string.Join(",", g.Select(x =>
x.ToString()).ToList()));