我在用 C# 编程我需要把一些东西放在一个字符串'xml'中
我有以下代码
TextBox[] myTextBoxes = new TextBox[] { this.textBox2, this.textBox3, this.textBox4, this.textBox5, this.textBox6, this.textBox7, this.textBox8, this.textBox9, this.textBox10, this.textBox11 };
TextBox[] ValueBoxes = new TextBox[] { this.textBox3, this.textBox5, this.textBox7, this.textBox9, this.textBox11 };
CheckBox[] myCheckBoxes = new CheckBox[] { this.checkBox2, this.checkBox4, this.checkBox6, this.checkBox8, this.checkBox10 };
CheckBox[] myMandBoxes = new CheckBox[] { this.checkBox3, this.checkBox5, this.checkBox7, this.checkBox9, this.checkBox11 };
并验证我的某些条件
xml += "<fields>";
for (int i = 0; i < myTextBoxes.Length; i++)
{
if (string.IsNullOrWhiteSpace(myTextBoxes[i].Text))
{
if (myCheckBoxes[i].Checked == true)
xml += "<field display='yes'> ";
else
xml += "<field display='no'> ";
if (myMandBoxes[i].Checked == true)
xml += "<mandatory='yes'>";
else
xml += "<Mandatory='no'>";
xml += "<label>" + (string)myTextBoxes[i].Text + "</label>";
}
}
它在 if (myCheckBoxes[i].Checked == true) 处给了我一个 Indexoutof boud 异常
我该如何解决这个问题