469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

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 6279
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jens Stjärna | last post: by
14 posts views Thread by vince | last post: by
10 posts views Thread by Jax | last post: by
2 posts views Thread by Rob Meade | last post: by
10 posts views Thread by netnet | last post: by
2 posts views Thread by =?Utf-8?B?RHJldw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.