I would like to split an array of objects into multiple array that hold no more than 10 elements.
Spent quite a while looking at examples, and the closest I can find is in C#:
Enumerable.Range(0, 100).Select((Value, Index) => new {Value, Index})
.GroupBy(p => p.Index/10)
.Select(g => g.Select(p => p.Value).ToList())
This runs and works in LinqPad, so I tried to convert it to VB.Net:
Enumerable.Range(0, 100).Select(Function(Value, Index) New With {Value, Index}) _
.GroupBy(Function(x) x.Index / 10) _
.Select(Function(g) g.Select(Function(p) p.Value).ToList())
But this doesn't give the same result, even though it looks like it should.
Obviously this is just an example and I would really like it to work on an array of customs objects. (Bonus points: why aren't these two examples equivalent?).
But this doesn't give the same result: then: what does it give? Wherein does it differ? My guess (been a long time since VB): the division results in doubles instead of integers?.Select(...)after theGroupBy()"strips" the keys from the GroupBy result so probably the easiest would be storing the intermediate results in a variable and first looking at that (likefoo = Enumerable....GroupBy(...), then inspectfoowith the debugger).