arraylist question

How can I list the items in an arraylist. I have an arraylist populated with integers and I'd like to display the values in a label...
acdagirlAsked:
Who is Participating?
 
SanclerConnect With a Mentor Commented:
Not frantically serious ;-)

    Private Function JoinList(ByVal al As ArrayList) As String
        Return Join(Array.ConvertAll(CType(al.ToArray(GetType(Integer)), Integer()), New Converter(Of Integer, String)(AddressOf IntegerToString)), ",")
    End Function

    Private Function IntegerToString(ByVal i As Integer) As String
        Return i.ToString
    End Function

    YourLabelNameHere.Text = JoinList(YourArrayListNameHere)

Roger
0
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
Here's a small example

        Dim myArray As New ArrayList()
        myArray.Add("one")
        myArray.Add("two")
        myArray.Add("tree")

        For x As Integer = 0 To myArray.Count - 1
            MsgBox(myArray(x).ToString)
        Next x
0
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Dim str As String
For Each i As Integer In YourArrayListNameHere
    If str = "" Then
        str = i
    Else
        str = str & "," & i
    End If
Next
YourLabelNameHere.Text = str
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Very pretty Roger!

Array.ConvertAll() is only available in VB.Net 2005 though...
0
 
SanclerCommented:
Yes, I know.  And I only recently discovered it, which is why I couldn't resist seeing if I could build a nice one-liner (forgetting the Convertor) with it.

But, as I said, it wasn't intended for real for this case.

Roger
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It could be done as a "one-liner" in C# with anonymous methods:
http://msdn2.microsoft.com/en-us/library/0yw3tz5k(VS.80).aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.