Hi all
I'm trying to learn more about arraylist and how to use class.cs files, and I'm really stucked right now and would appreciate some help from you. I have a win form with 2 textboxes and 2 buttons and a few labels. I enter a surname and a lastname in each of the textboxes and click the first button. What I try to achieve is that both names will be collected in an arrayList, and let say I enter 5 different names and then I have a second button when I click that button I want to populate a label with those 5 names from my arrayList. Here is my code from form1.cs:
public void controllButton_Click(object sender, EventArgs e)
{
Person NewPerson = new Person();
NewPerson.lastname = lastNameTextBox.Text;
NewPerson.surname = surNameTextBox.Text;
string sname = NewPerson.surname;
string lname = NewPerson.lastname;
NewPerson.Historian();
}
private void historicButton_Click(object sender, EventArgs e)
{
Person NewPerson2 = new Person();
NewPerson2.Hist();
label1.Text = NewPerson2.lastname;
}
And here is my code from Person.cs:
class Person
{
static ArrayList Historik = new ArrayList();
public string lastname;
public string surname;
public string Lastname
{
get { return this.lastname; }
set { this.lastname= value; }
}
public string Surname
{
get { return this.surname; }
set { this.surname= value; }
}
public void Historian()
{
Historik.Add(lastname);
Historik.Add(surname);
}
public string Hist()
{
foreach (Person s in Historik)
{
return s.lastname;
}
}
}
I hope someone could help me with this, thank you.

1 answers
Try it like this:
answered 2 years ago by:
17279
60
Hi Vulpes, you are great as usual...Thank you very much.