Create Linq query - EF List with n sublists

2

I have a list with N results, I would need to make some changes in linq so this list would return N lists of only 3 underlying results. Any idea?

    
asked by anonymous 23.02.2016 / 14:19

1 answer

2

You can use the following code:

    var resultados = lista.Select((x, i) => new { Index = i, Value = x })
                .GroupBy(x => x.Index / 3)
                .Select(x => x.Select(v => v.Value).ToList())
                .ToList();

With this you break your list into N lists of 3 results.

    
23.02.2016 / 14:21