Enumerable.Chunk<TSource>(IEnumerable<TSource>, Int32) 方法

定义

将序列的元素拆分为最多 size大小的区块。

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

类型参数

TSource

source 的元素类型。

参数

source
IEnumerable<TSource>

IEnumerable<T> 分块的元素的 。

size
Int32

每个区块的最大大小。

返回

IEnumerable<TSource[]>

一个 IEnumerable<T> ,它包含输入序列拆分为大小 size区块的元素。

例外

sourcenull

size 低于 1。

注解

每个区块(最后一个区块除外)的大小为 size。 最后一个区块将包含剩余的元素,并且可能较小。

适用于

产品 版本
.NET 6, 7, 8, 9

另请参阅