I have Object A in which I have lengths. I would like to order by length descending, then I would like to group them by threes and return that list of a list of objects.
I can get the grouping to work, but all i get is the key of the grouping and not the items.
public class a
{
public string Id { get; set; }
public int Length { get; set; }
}
List<a> c = Instantiate a list
c.OrderByDescending(x => x.Length)
.Select((e, i) => new { Item = e, Grouping = (i / 3) })
.GroupBy(x => x.Grouping)
.Select(x => x.Key)
.ToList()
I think it has something to do with my group by but I cant seem to get it to work. What I would like is a List<List<a>>
that have at most three items.