Create a dictionary on a list with grouping

前端 未结 4 1598
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 08:51

I have the following object in a list:

public class DemoClass
{
    public int GroupKey { get; set; }
    public string DemoString { get; set; }
    public o         


        
4条回答
  •  执笔经年
    2020-12-04 09:27

    var groupedDemoClasses = (from demoClass in mySepcialVariableWhichIsAListOfDemoClass
                              group demoClass by demoClass.GroupKey
                              into groupedDemoClass
                              select groupedDemoClass).ToDictionary(gdc => gdc.Key, gdc => gdc.ToList());
    

    This one will work !!!

提交回复
热议问题