Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ArrayList of Objects

Posted on 2006-06-15
3
Medium Priority
?
226 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:codeshelp
  • 2
3 Comments
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 16914471
string address = personObjectAL[2].address;
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 400 total points
ID: 16914518
sorry you need to cast the Object to a Person object first, it should be:

string address = ((Person) personObjectAL[2]).address;
0
 
LVL 3

Author Comment

by:codeshelp
ID: 16914614
Thank you!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question