My goal is to add newly created Student's parameters from TextBox to List collection.
As far as I understand, the code below does not do so.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
btnCreateStudent.Click += btnCreateStudent_Click;
}
private void btnCreateStudent_Click(object sender, RoutedEventArgs e)
{
Student student = new Student();
student.Name = txtFirstName.Text;
student.Surname = txtLastName.Text;
student.City = txtCity.Text;
student.Students.Add(student);
txtFirstName.Text = "";
txtLastName.Text = "";
txtCity.Text = "";
}
class Student
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string surname;
public string Surname
{
get { return surname; }
set { surname = value; }
}
private string city;
public string City
{
get { return city; }
set { city = value; }
}
public List<Student> Students = new List<Student>();
}
}
List, or aListBox?