LINQ query — Data aggregation (group adjacent)
You can use Linq’s GroupBy in a modified version which groups only if the two items are adjacent, then it’s easy as: var result = classes .GroupAdjacent(c => c.Value) .Select(g => new { SequenceNumFrom = g.Min(c => c.SequenceNumber), SequenceNumTo = g.Max(c => c.SequenceNumber), Value = g.Key }); foreach (var x in result) Console.WriteLine(“SequenceNumFrom:{0} SequenceNumTo:{1} Value:{2}”, … Read more