Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the highest value from one list to sort the second list.
    primarykey
    data
    text
    <p>There are two lists.</p> <p>I have a list of students, made like this</p> <pre><code>List&lt;Student&gt; students = new List&lt;Student&gt;(); </code></pre> <p>The properties of each student object in the list are firstName, LastName, and Fees[]. </p> <p>Fees is an array that holds a set of fees for each student in the list.</p> <p>I made a second list like this: </p> <pre><code>List&lt;double&gt; totals = new List&lt;double&gt;(); </code></pre> <p>I loop through the list of students and add up the fees for each. Then I add the totals for each student to the <code>totals</code> list (My second list).</p> <p>Now I need to sort the <code>students</code> list so the highest total amount due in fees is at the beginning. In other words, I need to sort <code>students</code> using the highest value in <code>totals</code>. I can get the highest value out of <code>totals</code> like this:</p> <pre><code>double highestTotalAmountDue = totals.Max(); </code></pre> <p>How do I use this <code>highestTotalAmountDue</code> value to sort the <code>students</code> list so that the student with the highest fee total is at the beginning of the list??</p> <p>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.</p> <p>Here is my code so far: </p> <pre><code>List&lt;double&gt; totals = new List&lt;double&gt;(); double tempTotal = 0; Lis&lt;Student&gt; students = new Lis&lt;Student&gt;(); // populate the students list foreach (var item in students) { for (var i = 0; i &lt; 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???? </code></pre> <p>Please help. Thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload