There are two lists.
I have a list of students, made like this
List<Student> students = new List<Student>();
The properties of each student object in the list are firstName, LastName, and Fees[].
Fees is an array that holds a set of fees for each student in the list.
I made a second list like this:
List<double> totals = new List<double>();
I loop through the list of students and add up the fees for each. Then I add the totals for each student to the totals
list (My second list).
Now I need to sort the students
list so the highest total amount due in fees is at the beginning. In other words, I need to sort students
using the highest value in totals
. I can get the highest value out of totals
like this:
double highestTotalAmountDue = totals.Max();
How do I use this highestTotalAmountDue
value to sort the students
list so that the student with the highest fee total is at the beginning of the list??
Just to clarify, I only need to add the student with the highest fee total at the top of the list. The rest can remain in the same order.
Here is my code so far:
List<double> totals = new List<double>();
double tempTotal = 0;
Lis<Student> students = new Lis<Student>();
// populate the students list
foreach (var item in students)
{
for (var i = 0; i < resultSet[0].Fees.Length; i++)
{
tempTotal += item.Fees[i].Amount;
}
totals.Add(tempTotal);
tempTotal = 0;
}
double highestTotalAmountDue = totals.Max();
// now what to do to sort the students list by highestTotalAmountDue to put the student with the highest fee due at the top????
Please help. Thanks in advance.