473,698 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Ejemplo 1");
al.Add("Ejemplo 2");

It can store two string in ArrayList, my question is

ArrayList can Store Classes ?

Thanks.
Nov 15 '05 #1
3 1711
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*******@yaho o.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi People
Few day ago, somebody sent me this code.

ArrayList al = new ArrayList();
//Insertar datos en la lista:
al.Add("Ejemplo 1");
al.Add("Ejemplo 2");

It can store two string in ArrayList, my question is

ArrayList can Store Classes ?

Thanks.

Nov 15 '05 #3

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

ArrayList al = new ArrayList();
//Insertar datos en la lista:
al.Add("Ejemplo 1");
al.Add("Ejemplo 2");

It can store two string in ArrayList, my question is

ArrayList can Store Classes ?


ArrayList al = new ArrayList();
...
al.Add("Ejemplo 1");
...
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.Collecti ons-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
7168
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 implement this putFieldAt below when I have field object that should be placed at position row i and kolumn j. So this putFieldAt is called 64 timmes where i has the value from 0 to 7 and j has value from 0 to
1
3334
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 j=1;j<=12;j++) {if(j<10)
11
3606
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 million lines. b) I need to store the contents into a unique hash. c) I need to then sort the data on a specific field. d) I need to pull out certain fields and report them to the user.
10
1767
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 once the object is created? I thought they would simply be added to an ArrayList, but this doesn't seem to be working. eg:
3
4433
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 decided that the most effective way would be : When i connect to the server once, I download the list and disconnect, instead of connecting every time i go, to the lower node in my tree hierarhy. Thus i have a problem - how to store data.
3
1394
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 where I shuld store the questions and answers. and how application can pick randomly question. right now I have all question in a text file. Please give me suggestion. I am using C# and asp.net for this. Regards, Sukh.
4
1258
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 several routines that are identical, except for the object type and database action specific to that particular class, such as "Public ReadOnly Property Item(ByVal SystemID As Integer) As CEmployee" or "Public Shared Function Save(ByVal TheItem As...
3
4095
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 I ask for your advice. Here is my page load. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
1
1347
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 arraylist and detach all the event handlers. My problem is that I don't know which information to store. When removing the handlers in a loop, the most important thing is that I don't want to distinguish between the different object types and events,...
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.