Split List into Sublists with LINQ

前端 未结 30 2377
灰色年华
灰色年华 2020-11-21 06:26

Is there any way I can separate a List into several separate lists of SomeObject, using the item index as the delimiter of each s

30条回答
  •  隐瞒了意图╮
    2020-11-21 07:08

    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();
    

提交回复
热议问题