Printing specific arrays from arraylist (C#)

Associate
Joined
22 May 2011
Posts
1,445
Location
Edinburgh
Hey all!

Basically I have a program which is importing 600 sets of data (5 pieces per set).

On the GUI is an option to specify then specific element of this set, however I cannot get it to print the elements, within the arraylist element... If that makes sense.

I do:

label1.Text = ArrayList[element].ToString();

However this simply sets the label to:

namespace.array

Can anyone help?
 
What's in the ArrayList? Your title makes it sound like you're storing Arrays in your ArrayList?

Also, why are you using ArrayList in the first place? That's pretty much been deprecated since generics were introduced back in 2005.
 
Firstly, I would use List<T> rather than ArrayList.
Secondly, I would question the fact you're storing arrays in a list in the first place - what exactly are you trying to do?

The code you posted above will take a particular element of your ArrayList, which will be an array and then calls ToString() on that array.
By default that will just give you the name of the type, which is why you're seeing something that looks like the type of the array.

It sounds like you want a particular element within the array, so you'd need to do a further dereference.
Some more information about what you're trying to achieve/more of your code would definitely be useful here.

If I had to guess I'd say something like this is more what you're after

Code:
label1.Text = string.Join(",", ArrayList[element]);
 
Last edited:
Back
Top Bottom