Assign Arraylist into Arraylist

  • Thread starter Thread starter Grey
  • Start date Start date
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..
 
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..
 
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
 
If you do this, think about the
System.Collections.Specialized.StringCollection for a type-safe string
collection.

-mike
MVP
 
Back
Top