您好,我正在尝试将动态文本框中的一些数据保存到 XML 文件中。但每次我尝试我都会收到这个错误
“索引超出范围。必须为非负数且小于集合的大小。参数名称:索引”
XmlDocument document = new XmlDocument();
document.Load(@"myGrades.xml");
for (int i = 0; i < 7; i++)
{
**TextBox tb1 = (TextBox)textboxComputer[i];** //<- error is thrown here
string markGained = tb1.Text;
this.Text = markGained;
XmlElement root = document.DocumentElement;
XmlElement newAssessmentMark = document.CreateElement("Assessment");
XmlElement newMark = document.CreateElement("AssessmentMark");
XmlText mark = document.CreateTextNode(markGained);
newAssessmentMark.AppendChild(newMark);
newMark.AppendChild(mark);
XmlNode parentNode = document.SelectSingleNode("myGrades/courseStructure/level4");
parentNode.InsertAfter(newAssessmentMark, parentNode.LastChild);
document.Save(@"myGrades.xml");
}
this.Close();
帮助表示赞赏:)