Click or drag to resize

XEnumerableBatchTSource Method

Splits the input sequence into a sequence of batches of the specified size.

Namespace:  Linq.Extras
Assembly:  Linq.Extras (in Linq.Extras.dll) Version: 5.0.0+96a4f4bfed64095342c5df107c1fe1fb95603ee5
Syntax
public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(
	this IEnumerable<TSource> source,
	int size
)

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
The sequence to split into batches.
size
Type: SystemInt32
The size of the batches

Type Parameters

TSource
The type of the elements of source.

Return Value

Type: IEnumerableIEnumerableTSource
A sequence of batches of the specified size; the last batch can be shorter if there isn't enough elements remaining in the input 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).
See Also