I am trying to do aggregate functions in a list of generics in C# based on an id
class Student{
public int id { get; set; }
public int marks { get; set; }
}
class Main {
List<Student> StudentList = new List<Student>();
List.Add(new Student(1,55);
List.Add(new student(2,65);
List.Add(new student(4,75);
List.Add(new student(1,65);
List.Add(new student(2,45);
foreach(var st in StudentList) {
Console.WriteLine(st.id + " " + st.marks);
}
}
But this returns
1 55
2 65
4 75
1 65
2 45
I want to return the following result:
1 120
2 110
4 75