ArrayList of Objects

Hey Experts,

I have an object\class(Person.cs) with the following data:
private int age;
private string name;
private string address;
...

In another class, I:
ArrayList personObjectAL = new ArrayList( );
loop (add 10 people)
  {
     Person person = new Person( );
     person.age = age;
     person.name = name;
     person.adddres = address;
     ...
     personObjectAL.Add(person)
   }

How do I get the address of the 3rd entry?

Thank you!
LVL 3
codeshelpAsked:
Who is Participating?
 
Ravi SinghConnect With a Mentor Senior Software EngineerCommented:
sorry you need to cast the Object to a Person object first, it should be:

string address = ((Person) personObjectAL[2]).address;
0
 
Ravi SinghSenior Software EngineerCommented:
string address = personObjectAL[2].address;
0
 
codeshelpAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.