Hi I have a list of element of class type class1 as show below. How do I group them into a
Dictionary
based on the group
It will be more efficient to replace:
gdc => gdc.ToList()[0].groupID
with:
gdc => gdc.Key
Other than that, it looks like I would have done.
Alternately, if you are okay with extension methods over LINQ (I personally prefer them), it can be shortened further still with:
var t = data.GroupBy(data => data.groupID).ToDictionary(gdc => gdc.Key, gdc => gdc.ToList());