I am running a very simple program that must get input from a couple of textboxes and store that as a record in an ArrayList and later I want to display every record in a message box and in list box.
The problem I am having is that I am unable to show all record in the ArrayList. Only the last record gets to be display a number of time equivalent to the number of items contained in the ArrayList.
What am I doing wrong?
Below is the code I am using.
public partial class TheForm : Form
Person myPerson = new Person();
ArrayList Friends = new ArrayList();
private void btnExit_Click(object sender, EventArgs e)
private void btnGetName_Click(object sender, EventArgs e)
myPerson.FirstName = txtFirstName.Text;
myPerson.LastName = txtLastName.Text;
MessageBox.Show("The name entered is " + myPerson.FirstName + " " + myPerson.LastName);
txtFirstName.Text = "";
txtLastName.Text = "";
private void btnShowContent_Click(object sender, EventArgs e)
//listBoxFriends.DataSource = Friends;
foreach (Person myPerson in Friends)
listBoxFriends.Items.Add(myPerson.FirstName.ToString() + " " + myPerson.LastName.ToString());
MessageBox.Show(myPerson.FirstName.ToString() + " " + myPerson.LastName.ToString() );