title: Adding items to an array using a foreach loop in C#
body: <p>I am trying to do a homework assignment that requires using a foreach loop to add items to an array. I did it using a for loop but cannot figure it out with a foreach loop.</p>
  
  <p>Here is what I need, just in a foreach loop instead.</p>
  
  <pre><code>for (int i = 0; i &lt; 5; i++)
          {
              Console.Write("\tPlease enter a score for {0} &lt;0 to 100&gt;: ",  studentName[i]);
              studentScore[i] = Convert.ToInt32(Console.ReadLine());
              counter = i + 1;
              accumulator += studentScore[i];
          }
  </code></pre>
  
  <p>Sorry if this has been asked but I could not find an answer that helped me.</p>