Getting average value of groups with LINQ

后端 未结 2 1463
轮回少年
轮回少年 2020-12-19 12:42

I am trying to split my List into different groups based on a certain value each item in the List has, and then find the average of another value in those groups.

T

2条回答
  •  借酒劲吻你
    2020-12-19 13:25

    Check this out:

    students.GroupBy(s => s.Level, s => s.GPA, 
                    (level, scores) => new { Level = level, Avg = scores.Average() }
    

提交回复
热议问题