using System.Collections.Generic;
public class StudentScore
public string StudentName { get; set; }
public int Score { get; set; }
public class StudentScoreSum
public string StudentName { get; set; }
public int ScoreSum { get; set; }
public static void Main(string[] args)
List<StudentScore> dbScores = new()
new() { StudentName = "Bob", Score = 5 },
new() { StudentName = "Bob", Score = 5 },
new() { StudentName = "Bob", Score = 5 },
new() { StudentName = "John", Score = 4 },
new() { StudentName = "John", Score = 4 },
new() { StudentName = "Michael", Score = 3 },
new() { StudentName = "Michael", Score = 3 },
new() { StudentName = "Michael", Score = 4 }
List<StudentScoreSum> scoreSum = dbScores
.GroupBy(s => s.StudentName)
.Select(scoresByStudent => new StudentScoreSum {
StudentName = scoresByStudent.Key,
ScoreSum = scoresByStudent.Sum(s => s.Score)})
Console.WriteLine(string.Join(Environment.NewLine, scoreSum.Select(s => $"{s.StudentName}: {s.ScoreSum}")));