I must convert from python language to C# some code and I'm having difficulties with one part of it.
def split_data(seq, length):
return [seq[i:i + length] for i in range(0, len(seq), length)]
print(split_data([4,5,6,8,5],2))
The purpose of this code is to give an int array in parameters and split it in arrays of the length parameter. For instance here the result of this print will be : [[4, 5], [6, 8], [5]]
The thing is I need to have the same thing in C#.
So I started to create a List<int[]>
. I know how to add int[] inside of it but I have no idea how to split them as in Python, especially using this length parameter.
I tried to achieve it using for, foreach loops or even IEnumerable but I couldn't make it work
Maybe there is a very easy way to finish it or something I didn't notice yet. My low knowledge about C# is not helping me either :).
Thanks for your help anyway.