473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Store Classes in ArrayList

Hi People
Few day ago, somebody sent me this code.

ArrayList al = new ArrayList();
//Insertar datos en la lista:
al.Add("Ejemplo1");
al.Add("Ejemplo2");

It can store two string in ArrayList, my question is

ArrayList can Store Classes ?

Thanks.
Nov 15 '05 #1
3 1696
Pablo Salazar wrote:
ArrayList can Store Classes ?


An ArrayList can store references to anything.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
Like Frank said, you can store anything. If you look at the .Add
method..you'll see it can take an Object as a parameter
http://msdn.microsoft.com/library/de...ClassTopic.asp ,
hence, anything you want to stick in there is fair game.
"Pablo Salazar" <pa*******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi People
Few day ago, somebody sent me this code.

ArrayList al = new ArrayList();
//Insertar datos en la lista:
al.Add("Ejemplo1");
al.Add("Ejemplo2");

It can store two string in ArrayList, my question is

ArrayList can Store Classes ?

Thanks.

Nov 15 '05 #3

"Pablo Salazar" <pa*******@yahoo.com> wrote in message
news:#g**************@TK2MSFTNGP10.phx.gbl...
Hi People
Few day ago, somebody sent me this code.

ArrayList al = new ArrayList();
//Insertar datos en la lista:
al.Add("Ejemplo1");
al.Add("Ejemplo2");

It can store two string in ArrayList, my question is

ArrayList can Store Classes ?


ArrayList al = new ArrayList();
...
al.Add("Ejemplo1");
...
al.Add(new Person("Jack", ...));
...
al.Add(new Car(NumberPlate, "Ford", ...));
...
al.Add(new Book("I Ching", ...));
...

In fact, any System.Object-derived class instance may be stored in a
System.Collections-contained collection. You can check each stored object's
type before 'extracting' it:

foreach (System.Object o in al)
{
if (o is Book)
{
Book b = (Book) o;
...
}
else if (o is Car)
{
Car c = (Car) o;
...
}
...
}

You may care to check out the relevant documentation for more details.

I hope this helps.

Anthony Borla
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tony Johansson | last post by:
Hello! Assume you want to store field object that a chess board consist of. A chess board consist of 64 fields where each field is either white or black. Now to my question how should I...
1
by: Vaj | last post by:
Hi, I'm attaching a code here.this code works successfully, But my doubt is, Can an arraylist store this integer value "J" as wellas string value "S" ArrayList ArrMM=new ArrayList(); for(int...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
10
by: Craig Lister | last post by:
I'm a newbie.. I'm trying to list all files in a directory, and store them in a aFile object. As I iterate through each file, I store the size, name, path, date etc... How do I store them...
3
by: piotrek | last post by:
Hi I would like to ask you a question. Ian creating app. that download from server directory structure ( whole tree ) and those data are placed in proper places into my treeview control. I...
3
by: Sukh | last post by:
I have to design a "Online Test Application" and application is going to display question and answers.All the questons are objective type so there is four answer for each question. My Question is...
4
by: Confused Newbie | last post by:
I'm converting an app written in VB 2003 to 2005 and need advice for how to deal with this situation: The app has a number of "manager" classes that handle the data access. They all have...
3
by: ricardo.sobral.santos | last post by:
Hi there, I cannot store an arraylist in a session. I have read some posts and still found no solution. I am sure it might be something simple, but since I have been around it for quite sometime...
1
by: Armin Zingler | last post by:
Hi, I add event handlers to different events of objects of different type. In an array or arraylist, I want to store the information about which events I added. Later, I want to process the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.