Assign Arraylist into Arraylist

G

Grey

i have succeed to assign one ArrayList into another ArrayList, i.e.
PcNameVirusDef.Add (Rec[0].ToString());
PcNameVirusDef.Add (Rec[4].ToString());
arPcNameVirusDef.Add(PcNameVirusDef);

But when I try out extract back the value, i.e.
arPcNameVirusDef[0][0].toString();
I got error....In fact, how to get the value and is it possible to do that in C#...as I tried this approach with Collection in VB6..
 
W

William Ryan eMVP

If I understand your objective, I thing using
arPcNameVirusDef.Addrange(PcNameVirusDef); should work for you.

You can do anything in C# that you can with VB.NET with very limited
exceptions, but I'm not sure what the ultimate goal is...let me know and
I'll walk you through it.

HTH,

Bill
i have succeed to assign one ArrayList into another ArrayList, i.e.
PcNameVirusDef.Add (Rec[0].ToString());
PcNameVirusDef.Add (Rec[4].ToString());
arPcNameVirusDef.Add(PcNameVirusDef);

But when I try out extract back the value, i.e.
arPcNameVirusDef[0][0].toString();
I got error....In fact, how to get the value and is it possible to do that
in C#...as I tried this approach with Collection in VB6..
 
M

Morten Wennevik

Hi Grey,

The ArrayList returns an object for the indexer, so you have to cast it
back

String s = (string)((ArrayList)arPCNameVirusDef[0])[0];

Or for easy reading.

object o = arPCNameVirusDef[0];
ArrayList a = (ArrayList)o;

o = a[0];
String s = (string)o;

Happy coding!
Morten
 
M

Michael Giagnocavo [MVP]

If you do this, think about the
System.Collections.Specialized.StringCollection for a type-safe string
collection.

-mike
MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Comparing ArrayLists 5
ArrayList with structur as element 1
ArrayList 12
ArrayList pass to method 4
ArrayList accessed by string 4
using ArrayList with object 11
ArrayList 7
inconsistent ArrayList sort results 2

Top