我在用不同类中存储的信息填充列表框时遇到了问题。这个类被称为TeacherTools,这是许多方法用来控制该列表中的学生对象的地方。在不同的类中访问列表
我想要做的是基本上将学生的名字添加到列表中,但我不确定语法。
public partial class TeacherTools : Window
{
private List<Student> studentList = new List<Student>();
public List<Student> Kids
{
get { return studentList; }
set { studentList = value; }
}
}
public partial class MainWindow : Window
{
private void beginTest(object sender, RoutedEventArgs e)
{
foreach (Student s in Kids) //Unsure here
{
studentsList.Items.Add(s.Name);
}
}
}
谢谢您的时间
如何'MainWindow'和'TeacherTools'有关? –
无论如何,他们都是独立的窗口,如果这就是你的意思。 – Melky
“不确定”?我会建议[实例化类]的基本教程(http://csharp.net-tutorials.com/reflection/instantiating-a-class/)。 –