c# - Create a list of objects by grouping on multiple properties -
i have list<t>
t
custom object cow
. right use following code split list based on color
.
cowgroups = x in cows group x x.color y select y.tolist().tolist();
then take cowgroups
, run foreach
on set of actions each cow
. list comes out ienumerable<list<cow>>
what i'm trying do double grouping on initial list<cow>
can group base on color , size. result should still ienumerable<list<cow>>
, each list<cow>
made based on combined pair of color , size.
a co-worker recommended tolookup
approach, returns list of key/value pairs, , can't seem value part of pair.
i guess i'm looking either way go straight collection of lists, or turn result of tolookup
approach collection of lists.
you can group class contains both attributes:
group x new { x.color, x.size } y
Comments
Post a Comment