473,386 Members | 1,958 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,386 software developers and data experts.

Add objects in arraylist

Hi,

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

test myTest = new test();
myTest.myList.Add(<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 6399
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.com

"Arjen" <bo*****@hotmail.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.Add(<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.Collections;
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.Add(ds);
DataSet ds2 = (DataSet)myTest.myList[0];
Console.WriteLine(ds2.DataSetName );
Console.ReadLine();
}
}
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.Add(<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.com> schreef
in bericht news:u9*************@TK2MSFTNGP15.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.com

"Arjen" <bo*****@hotmail.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.Add(<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
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...
14
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
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...
5
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...
16
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...
2
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...
14
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...
10
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.