good morning!
i have the following object in a list:
public class DemoClass
{
public int GroupKey { get; set; }
public string DemoString { get; set; }
public object SomeOtherProperty { get; set; }
}
now i want to create following dictionary out of it:
Dictionary<int, List<DemoClass>>
following behaviour is tried to applied: group the List by the property GroupKey
somehow i don't get this done and some help would be appreciated!
regards!
edit:
after thinking a bit, i achieved the neede behaviour with:
var groupedDemoClasses = from demoClass in mySepcialVariableWhichIsAListOfDemoClass
group demoClass by demoClass.GroupKey
into groupedDemoClass
select groupedDemoClass;
var neededDictionary = groupedDemoClass.ToDictionary(gdc => gdc.Key, gdc => gdc.ToList());
but: isn't there any way to make this a "one-liner"?!