• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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;

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

Thank you!
  • 2
1 Solution
Ravi SinghSenior Software EngineerCommented:
string address = personObjectAL[2].address;
Ravi SinghSenior Software EngineerCommented:
sorry you need to cast the Object to a Person object first, it should be:

string address = ((Person) personObjectAL[2]).address;
codeshelpAuthor Commented:
Thank you!
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.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now