标记一个包含列表的Class对象
本文关键字:列表 包含 Class 对象 一个 | 更新日期: 2023-09-27 17:50:18
我有一个班的学生
字符串wholeName;列表& lt;
我从文本框中编译了一个对象:
private void button2_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
if (IsValidData())
{
List<string> result = txtScores.Text.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList();
Student student = new Student(txtName.Text, result.Select(int.Parse).ToList());
this.Tag = student;
this.Close();
}
在Form1的这一边我有这个:
private void btnAddNew_Click(object sender, EventArgs e)
{
AddNewStudent addStudentForm = new AddNewStudent();
DialogResult selectedButton = addStudentForm.ShowDialog();
addStudentForm.Tag = new Student();
if (selectedButton == DialogResult.OK)
student = addStudentForm.Tag as Student;
students.Add(student);
}
我应该从另一个表单中的用户信息中获取Tag来构建Student Student,并将其传递回Form1并将其添加到我的学生集合中。一旦它被添加,它的功能应该像我手动创建的学生当表单加载。相反,该列表在运行时为空。我甚至可以移动包含列表的整个对象通过标签如果可以,我哪里出错了?
你是覆盖标签值在addStudentForm。Tag = new Student();行