Is it okay to place "view = new Person"
within the button event handler? If I don't, and I place it within the Form1 constructor, only my last value gets added. Is that the proper way if I want to declare a new instance and then add it to my Arraylist?
private ArrayList store;
public Form1()
{
InitializeComponent();
store = new ArrayList();
}
private void Form1_Load(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{
//Is it okay to declare a new instance of the Person class
// with each button push?
Person view = new Person();
view.firstname = txtFirstName.Text;
view.lastname = txtLastName.Text;
store.Add(view);
txtFirstName.Clear();
txtLastName.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Person display in store)
{
MessageBox.Show(display.ToString());
}
}