标记包含列表的Class对象

时间:2014-03-15 05:51:39

标签: c# class object tags

我有一名学生

string wholeName; 列表< int> scoresList;

我将文本框中的对象学生编译成:

    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);

    }

我应该从其他表单中的用户信息中获取标签,以构建一名学生并将其传递回Form1并将其添加到我的学生集合中。一旦它被添加,它应该像我手动创建的学生一样在加载表单时起作用。而是在运行时期间列表为空。我甚至可以通过标签移动包含列表的整个对象,如果我可以在哪里出错?

1 个答案:

答案 0 :(得分:1)

你在添加学生Form.Tag = new Student();线

相关问题