title: C# Clearing Array not clearing not sure why
body: <p>I wrote this program using Arrays in C#. It's homework. I pretty much have everything written in the program but I am stuck on clearing the array. I thought I had it but I don't understand where it's not working.</p>
  
  <p>The program is pretty straightforward. The user enters a score and hits the "add" button. Then the user can enter more scores (anything 0 to 100). If the user chooses "Display" the program will sort the entered scores and display them in a messagebox (done)
  if the user presses the "Clear Scores" button the program should clear out the scores. I have it written to clear the text boxes, and I also wrote in there "Scores.Clear();" (Scores being the name of my list array) and then I returned the focus back to my scores entry text box so the user can enter another score. </p>
  
  <p>The book I am using simply says to clear type NameOfList.Clear(); so I'm stuck on why it's not clearing. I can tell it isn't because if I type more scores it will add the total instead of restarting. </p>
  
  <p>Here is my full program code. My clear starts about halfway down.</p>
  
  <p>Thank you in advance. </p>
  
  <pre><code>{
  public partial class frmScoreCalculator : Form
  {
      //declare a list array for scores
      List&lt;int&gt; Scores = new List&lt;int&gt;();
  
      //set total and average to 0 
      int Total = 0;
      decimal Average = 0;
  
  
      public frmScoreCalculator()
      {
          InitializeComponent();
      }
  
      //calculate the average by dividing the sum by the number of entries
      private decimal CalculateAverage(int sum, int n)
      {
          Average = sum / n;
  
          return Average;
      }
      private void frmScoreCalculator_Load(object sender, EventArgs e)
      {
  
      }
  
      //closes the program. Escape key will also close the program
      private void btnExit_Click(object sender, EventArgs e)
      {
          this.Close();
      }
  
  
      //clears the text boxes, clears the array, returns focus back to the score text box like a boss.
      private void btnClear_Click(object sender, EventArgs e)
      {
          txtScore.Text = "";
          txtCount.Text = "";
          txtTotal.Text = "";
          txtAverage.Text = "";
          Scores.Clear();
          txtScore.Focus();
      }
  
      //makes sure the score is within the valid range, calculates the average, adds to the number of
      //scores entered, and adds to the total
      private void btnAdd_Click(object sender, EventArgs e)
      {
          if (txtScore.Text == string.Empty)
          {
              txtScore.Focus();
              return;
          }
  
  
          int Score = int.Parse(txtScore.Text);
  
          if (Score &gt; 0 &amp;&amp; Score &lt; 100)
          {
              Scores.Add(Score);
  
              Total += Score;
              txtTotal.Text = Total.ToString();
  
              txtCount.Text = Scores.Count.ToString();
  
              Average = CalculateAverage(Total, Scores.Count);
              txtAverage.Text = Average.ToString();
  
              txtScore.Text = string.Empty;
              txtScore.Focus();
  
          }
  
          // if number is not valid, ask user for valid number
          else
          {
              MessageBox.Show("Please enter a number between 0 and 100.", "ENTRY ERROR, DO IT RIGHT!");
  
          }
  
          // returns focus to txtNumber
          txtScore.Focus();
          txtScore.Text = "";
      }
  
      //display button
      private void btnDisplay_Click(object sender, EventArgs e)
      {
          //sorts the scores low to high
          Scores.Sort();
  
          //displays scores in message box
          string DisplayString = "Sorted Scores :\n\n";
  
          foreach (int i in Scores)
          {
              DisplayString += i.ToString() + "\n";
          }
  
          MessageBox.Show(DisplayString);
      }
  }
  </code></pre>
  
  <p>}</p>