int i = 1;foreach (Control c in this.panel1.Controls){if (c is Label){c.Text = \"ok\"+i.ToString();i++;}}
赋值的顺序是根据Form1.Designer.cs
this.panel1.Controls.Add(this.button1);//foreach赋值顺序this.panel1.Controls.Add(this.label1);this.panel1.Controls.Add(this.label2);this.panel1.Controls.Add(this.label3);this.panel1.Controls.Add(this.label4);this.panel1.Controls.Add(this.label5);this.panel1.Controls.Add(this.label6);this.panel1.Controls.Add(this.label7);this.panel1.Controls.Add(this.label8);