Event anonymous function parameters not working correctly
<pre><code>PictureBox[,] picBoard = new PictureBox[3, 3];

for(int i = 0; i &lt; 3; i++)
    for (int j = 0; j &lt; 3; j++)
    {
        picBoard[i, j] = new PictureBox();
        picBoard[i, j].Click += new EventHandler(
          (sender, e) =&gt; Debug.WriteLine(i.ToString() + " " + j.ToString()));
    }
</code></pre>

<p>I am trying to make picBoard[i, j] print the position it has in the 2D array when clicked. The problem is that each PictureBox prints "3 3" when clicked. This doesn't make any sense to me, since i and j are never equal to 3. I tried replacing i with 500 in Debug.Writeline(), and it performs as expected ( always prints "500 3" ).</p>
