❔ LINQ: Group and extract all consecutive elements from List that match predicate

Example:
List<int> ints = new() {6,3,1,1,1,1,1,2,7,8,1,1,1,1,3,2,5,1,1,9,8,1,1,1,1,4,7,8,1}
var output = ints.GroupConsecutive().Where((g) => g.Key == 1); // Not a real function

foreach (var o in output) 
{
  Console.WriteLine(o.Count);
}

Expected output:
5
4
2
4
1


Is there such functionality in LINQ?
Was this page helpful?