arraylist question

Posted on 2007-07-23
Last Modified: 2010-04-23
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...
Question by:acdagirl
    LVL 48

    Assisted Solution

    Here's a small example

            Dim myArray As New ArrayList()

            For x As Integer = 0 To myArray.Count - 1
            Next x
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    Dim str As String
    For Each i As Integer In YourArrayListNameHere
        If str = "" Then
            str = i
            str = str & "," & i
        End If
    YourLabelNameHere.Text = str
    LVL 34

    Accepted Solution

    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)

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Very pretty Roger!

    Array.ConvertAll() is only available in VB.Net 2005 though...
    LVL 34

    Expert Comment

    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.

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    It could be done as a "one-liner" in C# with anonymous methods:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now