473,568 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add objects in arraylist

Hi,

public class test {
public ArrayList myList = new ArrayList();
}

test myTest = new test();
myTest.myList.A dd(<someobject> );

This results in an error.

I also tried to add objects inside a new arraylist.
And then set the new arraylist to the object arraylist.
test.myList = newarraylist;

This also results in an error.

How to add objects to this arraylist?

Thanks!
Nov 29 '05 #1
3 6416
Arjen,

You aren't being too specific about what the error is, or how you are
getting it.

Can you show some code? An arraylist should take anything that derives
from Object (meaning, anything) in the Add method.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Arjen" <bo*****@hotmai l.com> wrote in message
news:dm******** **@news4.zwoll1 .ov.home.nl...
Hi,

public class test {
public ArrayList myList = new ArrayList();
}

test myTest = new test();
myTest.myList.A dd(<someobject> );

This results in an error.

I also tried to add objects inside a new arraylist.
And then set the new arraylist to the object arraylist.
test.myList = newarraylist;

This also results in an error.

How to add objects to this arraylist?

Thanks!

Nov 29 '05 #2
Arjen
here is a "Short but Complete" (a-la Jon Skeet) example that works fine for
me:

using System;
using System.Collecti ons;
using System.Data;
namespace ArrayListTest
{
class TestMe
{
[STAThread]
static void Main(string[] args)
{
test myTest = new test();
DataSet ds = new DataSet();
ds.DataSetName= "TestDs";
myTest.myList.A dd(ds);
DataSet ds2 = (DataSet)myTest .myList[0];
Console.WriteLi ne(ds2.DataSetN ame );
Console.ReadLin e();
}
}
public class test
{
public ArrayList myList = new ArrayList();
}
}
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Arjen" wrote:
Hi,

public class test {
public ArrayList myList = new ArrayList();
}

test myTest = new test();
myTest.myList.A dd(<someobject> );

This results in an error.

I also tried to add objects inside a new arraylist.
And then set the new arraylist to the object arraylist.
test.myList = newarraylist;

This also results in an error.

How to add objects to this arraylist?

Thanks!

Nov 29 '05 #3
Whoops, when bug hunting I was looking at the wrong place.
the code was correct (what I was thinking)... I found the right place I
fixed the problem.

Thanks for your response!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> schreef
in bericht news:u9******** *****@TK2MSFTNG P15.phx.gbl...
Arjen,

You aren't being too specific about what the error is, or how you are
getting it.

Can you show some code? An arraylist should take anything that derives
from Object (meaning, anything) in the Add method.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Arjen" <bo*****@hotmai l.com> wrote in message
news:dm******** **@news4.zwoll1 .ov.home.nl...
Hi,

public class test {
public ArrayList myList = new ArrayList();
}

test myTest = new test();
myTest.myList.A dd(<someobject> );

This results in an error.

I also tried to add objects inside a new arraylist.
And then set the new arraylist to the object arraylist.
test.myList = newarraylist;

This also results in an error.

How to add objects to this arraylist?

Thanks!


Nov 29 '05 #4

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

Similar topics

3
13938
by: Jens Stjärna | last post by:
Hi. I have a question regarding the ArrayList. In my code I use the arraylist to store objects of certain class. I do not mix object types in the same ArrayList. public ArrayList adresses = new ArrayList(); I store only objects from the class "CAdresses" in this ArrayList. Now, every time I use the objects in the ArrayList I have to type...
14
14284
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
10
1746
by: Jax | last post by:
I dont seem to fully comprehend references to objects yet. Lets say for example I do this; Customer c = new Customer(); Customer c1 = c; I understand that if I change c1, I also change c as they are both referencing the same piece of data. But this isn't always the case it would seem. Sometimes I take a reference out, change it and then...
5
1395
by: hazz | last post by:
If this makes sense, I would like to convert an arraylist of objects returned from foo() into an array of the objects themselves per; private Customer customers; private int idx = 0; public CustomerQueueService() { customers = new Customer ; customers = foo(); //I want to copy the returned arraylist
16
6402
by: RCS | last post by:
So I have an ArrayList that gets populated with objects like: myAL.Add(new CustomObject(parm1,parm2)); I'm consuming this ArrayList from an ObjectDataSource and would like to have this support sorting (because it's ultimately being consumed in a GridView). I can't simply sort the ArrayList (because it only knows it's holding a bunch of...
2
4717
by: Rob Meade | last post by:
Dear all, I have a class which contains an arraylist populated with other objects, for example: PrescriptionQueue - containing multiple instances of Prescription I have the need on my web page to display this data which I have done, however, now I would like to sort it based on a data item/direction selected by the user from the web...
14
18736
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used CType for casting but it is throwing exception.
10
1883
by: netnet | last post by:
I have a collection of objects that I store in the session. Then I look in that collection to see if the collection.contains an object. it answers false. If I dont store that collection in the session it answers true. Is the session somehow modifying the collection? The objects look identical.
2
2623
by: =?Utf-8?B?RHJldw==?= | last post by:
I have a current requirement to all a subsidiary to use a current legacy application and interface with my new system to inject data when appropriate. I wanted to create a web service since we are both .Net shops and this would seem to be the easiest method. But I ran into one snafu. I wanted to return to the subsidiary an ArrayList of my...
0
7693
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...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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...
0
6275
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...
1
5498
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...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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...
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.