Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get "Value" property in IGrouping

The group implements IEnumerable<T> - In the general case, just call foreach over the group. In this case, since you need a List<T>:

list.Add(new DespatchGroup(group.Key, group.ToList());

There's no Values property or similar because the IGrouping<T> itself is the IEnumerable<T> sequence of values. All you need to do in this case is convert that sequence to a list:

list.Add(new DespatchGroup(group.Key, group.ToList());

For any selected group,you could call

var selectedGroupValues=selectedGroup.SelectMany(x=>x);

Just a related tip - since, as the other answers have said, the grouping is an IEnumerable, if you need to access a specific index you can use group.ElementAt(i).

This is probably obvious to a lot of people but hopefully it will help a few!


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!