Create batches in linq

前端 未结 16 1844
傲寒
傲寒 2020-11-22 02:50

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.

16条回答
  •  你的背包
    2020-11-22 03:52

    Another way is using Rx Buffer operator

    //using System.Linq;
    //using System.Reactive.Linq;
    //using System.Reactive.Threading.Tasks;
    
    var observableBatches = anAnumerable.ToObservable().Buffer(size);
    
    var batches = aList.ToObservable().Buffer(size).ToList().ToTask().GetAwaiter().GetResult();
    

提交回复
热议问题