title: "Index was outside the bounds of the array" in c#. Why?
body: <p>I keep getting an Exception in my for-each loop, and I don't understand why.  </p>
  
  <p>The error goes away when I make <code>array[i]</code> equal to <code>i</code>, but what if I want it equal to a different value?</p>
  
  <p>Relevant code:</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              int[] array1 = new int[5];
  
              for (int i = 0; i &lt; 5; i++)
              {
                  array1[i] = (i + 1);
              }
  
  
              foreach (int value in array1)
              {
                  Console.Write(array1[value]);
              }
  
              Console.ReadKey();
  
          }
      }
  }
  </code></pre>