LINQ in Action roller

The GroupAdjacent Extension Method

This is a bit of a geeky post for the LINQ and LINQ to XML folks. This post introduces a GroupAdjacent generic extension method that groups elements in a collection with adjacent elements based on a common key. For example, grouping the following array creates six groups (not 3, as with GroupBy): int[] ia = new int[] { 1, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0 }; GroupAdjacent groups them like this: Group 1 1 Group 0 0 0 Group 2 2 Group 0 0 0 0 Group 2 2 Group 0 0 0 0 In contrast, the standard GroupBy extension Read More...
Published Sunday, April 20, 2008 4:16 PM by Eric White's Blog
Anonymous comments are disabled

Featured Item

This Blog

Sponsoring

Syndication