Click or drag to resize

MoreEnumerableGroupAdjacentTSource, TKey, TElement Method (IEnumerableTSource, FuncTSource, TKey, FuncTSource, TElement)

Groups the adjacent elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 2.4.0
public static IEnumerable<IGrouping<TKey, TElement>> GroupAdjacent<TSource, TKey, TElement>(
	this IEnumerable<TSource> source,
	Func<TSource, TKey> keySelector,
	Func<TSource, TElement> elementSelector


Type: System.Collections.GenericIEnumerableTSource
A sequence whose elements to group.
Type: SystemFuncTSource, TKey
A function to extract the key for each element.
Type: SystemFuncTSource, TElement
A function to map each source element to an element in the resulting grouping.

Type Parameters

The type of the elements of source.
The type of the key returned by keySelector.
The type of the elements in the resulting groupings.

Return Value

Type: IEnumerableIGroupingTKey, TElement
A sequence of groupings where each grouping (IGroupingTKey, TElement) contains the key and the adjacent elements (of type TElement) in the same order as found in the source sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
This method is implemented by using deferred execution and streams the groupings. The grouping elements, however, are buffered. Each grouping is therefore yielded as soon as it is complete and before the next grouping occurs.
See Also