Click or drag to resize

MoreEnumerable.Segment<T> Method (IEnumerable<T>, Func<T, Int32, Boolean>)

Divides a sequence into multiple sequences by using a segment detector based on the original sequence

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 2.6.0
Syntax
public static IEnumerable<IEnumerable<T>> Segment<T>(
	this IEnumerable<T> source,
	Func<T, int, bool> newSegmentPredicate
)

Parameters

source
Type: System.Collections.Generic.IEnumerable<T>
The sequence to segment
newSegmentPredicate
Type: System.Func<T, Int32, Boolean>
A function, which returns true if the given element or index indicate a new segment, and false otherwise

Type Parameters

T
The type of the elements in the sequence

Return Value

Type: IEnumerable<IEnumerable<T>>
A sequence of segment, each of which is a portion of the original sequence

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<T>. 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).
Exceptions
ExceptionCondition
ArgumentNullException Thrown if either source or newSegmentPredicate are null.
See Also