我必須寫一個程序(C#,WPF),其中數據被從〜30個文本框檢索。我想通過循環文本框。我試圖創建文本框的數組,但由於每一個方法,我不得不多次重新初始化這個數組它沒有很好地工作。如何將多個文本框的內容讀取到數組中?
TextBox[] subjects = { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, textBox8, textBox9, textBox10 };
TextBox[] credits = { textBox11, textBox12, textBox13, textBox14, textBox15, textBox16, textBox17, textBox18, textBox19, textBox20 };
TextBox[] marks = { textBox21, textBox22, textBox23, textBox24, textBox25, textBox26, textBox27, textBox28, textBox29, textBox30 };
Subject.SubjectName = subjects[selection].Text;
Subject.AmountOfCredits= Convert.ToInt32(credits[selection].Text);
Subject.Mark = Convert.ToInt32(marks[selection].Text);
主要的問題是,如果有任何其他的方式來循環使用所有這些控件,而無需創建文本框的陣列?
在此先感謝。