I discovered a piece of code that should produce an error because the array goes out of bounds but instead it behaves strangely. When I step into it just stops after 4 loops and doesn't add the controls. How can this be, no errors or compiler warnings or anything?
Panel[] panel = new Panel[4];
Label[] label = new Label[4];
private void Form1_Load(object sender, EventArgs e)
{
for (int x = 0; x < 20; x++)
{
label[x] = new Label { Name = x.ToString("00"), BackColor = Color.Blue, Text = "Test" };
panel[x] = new Panel { Name = x.ToString("00"), BackColor = Color.Blue };
}
tableLayoutPanel1.Controls.AddRange(label);
tableLayoutPanel2.Controls.AddRange(panel);
}