Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ArrayList of Objects

Posted on 2006-06-15
3
Medium Priority
?
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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