Split List into Sublists with LINQ

前端 未结 30 2930
灰色年华
灰色年华 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 06:47

    We found David B's solution worked the best. But we adapted it to a more general solution:

    list.GroupBy(item => item.SomeProperty) 
       .Select(group => new List(group)) 
       .ToArray();
    

提交回复
热议问题