title: Getting top values from a list in c sharp
body: <p>So I'm having some trouble with a C# program that is meant to sum the 8 highness value from a list.</p>
  
  <p>The program works by declaring a variable <code>currenthigh</code>, which stores a value from the <code>gradelist</code>. It then compares itself to the value <code>abshigh</code> to see if it is greater than the established highest value. If it is, it sets <code>currenthigh</code> as the new highest value. </p>
  
  <p>Once the loop has run through the list and confirmed the highest value, it adds it to the <code>uppertotal</code> variable and uses the <code>ejector</code> variable to remove it from the list. The program then iterates, this time without the previous highest value. It iterates 8 times so that in the end the top 8 values are added to <code>uppertotal</code>.</p>
  
  <p>Trouble is, the highest variable remains in the list, despite the code having instructions to delete it, so it just adds the highest value to itself 8 times.</p>
  
  <pre><code>int currenthigh = 0;
  int abshigh = 0;
  int ejector = 0;
  int uppertotal = 0;
  
  for (int g = 0; g &lt; 8; g++)
  {
      for (int z = 0; z &lt; gradelist.Count; z++)
      {
          Console.WriteLine("PASS STARTED");
          currenthigh = Convert.ToInt32((gradelist[z]));
          Console.WriteLine("currenthigh" + currenthigh);
  
          if (currenthigh &gt; abshigh)
          {
              abshigh = currenthigh;
              ejector = z;
          }
  
      }
      Console.WriteLine("ejector" + ejector);
      uppertotal = uppertotal + currenthigh;
  
      gradelist.RemoveAt(ejector);
      Console.WriteLine("PASS COMPLETE");
      Console.WriteLine("RESETING");      
  }
  </code></pre>
  
  <p><em>Note - <code>gradelist</code> is a list of integers containing at least 12 items at all time.</em></p>