Split List into Sublists with LINQ

前端 未结 30 2395
灰色年华
灰色年华 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:57

    If the list is of type system.collections.generic you can use the "CopyTo" method available to copy elements of your array to other sub arrays. You specify the start element and number of elements to copy.

    You could also make 3 clones of your original list and use the "RemoveRange" on each list to shrink the list to the size you want.

    Or just create a helper method to do it for you.

提交回复
热议问题