title: IndexOutOfRange exception in multithreaded program
body: <p>I am not really comfortable with multi threaded programming and while I was trying to implement it in my code, was running into an exception which I am not able to figure out why. Any help in this would be greatly appreciated :)<br>
  So, basically I have this small snippet of code:  </p>
  
  <pre><code>string[][] Array1 = new string[thread_count][];
  
  /* Logic to insert data in Array1 */
  
  Thread[] WorkerThreads = new Thread[thread_count];
  
  for (int i = 0; i &lt; thread_count; i++)
  {
      /* THE EXCEPTION OCCURS IN THE FOLLOWING LINE */
      WorkerThreads[i] = new Thread(() =&gt; GetVal(Array1[i], val, num));
      WorkerThreads[i].Start();
  }
  
  for (int i = 0; i &lt; WorkerThreads.Length; i++)
      WorkerThreads[i].Join();  
  </code></pre>
  
  <p>Now, the value for thread_count is set to 10 and I am getting an IndexOutOfRange exception. The debugger shows the value of i as 10 and Array1[10][] is the one it is trying to access.<br>
  I am not getting how the value of i can reach 10 when the loop is not supposed to run that far.<br>
  Can anyone point out where am I going wrong? I am using C#.  </p>
  
  <p>Thanks </p>