Solved

ArrayList of Objects

Posted on 2006-06-15
3
219 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 100 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to read json value 2 52
performance tune IIS 10 on win 2016 that only runs one website 4 66
Printing 1 51
C# Desktop Application 3 36
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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