Queryable.Chunk<TSource>(IQueryable<TSource>, Int32) Method

Definition

Split the elements of a sequence into chunks of size at most size.

C#
public static System.Linq.IQueryable<TSource[]> Chunk<TSource>(this System.Linq.IQueryable<TSource> source, int size);

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IQueryable<TSource>

An IEnumerable<T> whose elements to chunk.

size
Int32

The maximum size of each chunk.

Returns

IQueryable<TSource[]>

An IEnumerable<T> that contains the elements the input sequence split into chunks of size size.

Exceptions

source is null.

size is below 1.

Remarks

Every chunk except the last will be of size size.

The last chunk will contain the remaining elements and may be of a smaller size.

Applies to

Product Versions
.NET 6, 7, 8, 9