Create Linq - EF List with n sublists

Asked

Viewed 69 times

2

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

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.