在 linq 中创建批处理 [英] Create batches in linq
本文介绍了在 linq 中创建批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以建议一种在 linq 中创建特定大小批次的方法吗?
Can someone suggest a way to create batches of a certain size in linq?
理想情况下,我希望能够以可配置数量的块执行操作.
Ideally I want to be able to perform operations in chunks of some configurable amount.
推荐答案
An Enumerable.Chunk()
扩展方法已添加到 .NET 6.0.
An Enumerable.Chunk()
extension method was added to .NET 6.0.
示例:
var list = new List<int> { 1, 2, 3, 4, 5, 6, 7 };
var chunks = list.Chunk(3);
// returns { { 1, 2, 3 }, { 4, 5, 6 }, { 7 } }
无法升级的,源代码可在 GitHub 上获得.
这篇关于在 linq 中创建批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文