I want to perform some calculations on my list List<StudentGrades> studentList
such as the average, mean, mode, etc.
The studentGrades
class has the following properties:
studentName
,midtermGrade
,finalExamGrade
.
How do I extract a certain property from the list and perform arithmetic operations on it?
The following code expands on the StudentGrades
class.
I'm thinking of using some sort of traversal technique to add the elements together, something like studentList.find(i).getMidtermScore
, which leads to my next question.
public class StudentGrades
{
public string studentName;
public int midtermGrade;
public int finalExamGrade;
public StudentGrades()
{
//initialize variables to 0 or ""
}
//some methods here
//example
private void getMidtermScore()
{
return this.midtermGrade;
}
public string toString()
{
string result = "student: " + studentName + " midterm grade: " + midterm + ...etc;
return result;
}
}
Also, how does someone grab an element at a specific index from a list?
In Java, for ArrayLists
or Lists
, we use the get(//some value)
method to do so.
Looking at the Microsoft docs documentation for C# list, the counterpart is the find()
method? Not really sure.