So I have a set of variables in an array, and I would like to collect the data from every of (let's say) 4th index. For example if I have array all[] which has data at [0]->id [1]->field1 [2]->field2
and after a [3]->linebreak
and after another set of [4]->id [5]->field1
and [6]->field2 [7]->linebreak
and so on and so forth. Now I'd like to create an array(or a list) called id[] which would have all the id's in it and a field1[]
which would have all the field ones. How could I do this?
You can apply modulo 4 on the index of each array element to determine its position along its group-of-four. Ids would be in position 0; fields would be in position 1 and 2.
int[] ids = all.Where((_, i) => i % 4 == 0).ToArray();
int[] fields = all.Where((_, i) => i % 4 == 1 || i % 4 == 2).ToArray();