0

Is there an elegant way to split a list into two chunks at a specified index?

For example my list looks as followed:

[-4, 0, 2, 18, 22, 67, 51]

I want to get two lists, namely:

[-4, 0, 2]

[18, 22, 67, 51]

So the specified index would be 2 (so that the 2nd list starts after the value 2).

Thanks for help

  • Trivially for this specific question: `int index = 2; var list1 = originalList.Take(index+1).ToList(); var list2 = originalList.Skip(index+1).ToList();` – Matthew Watson Jan 19 '23 at 14:37
  • loop through the list while checking the index , if the index is equal to 2, add the earlier elements to a new list and break – Son of Man Jan 19 '23 at 17:08

0 Answers0