We help IT Professionals succeed at work.

Vb.net Arraylist

rflorencio
rflorencio asked
on
How can make an arraylist with 3 columns, eg.

"red",4,"r"
"blue",5,"b"
Comment
Watch Question

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
You can put anything in an ArrayList...how about an Array of Object?

        Dim arrList As New ArrayList
        arrList.Add(New Object() {"red", 4, "r"})
        arrList.Add(New Object() {"blue", 5, "b"})

        For Each row() As Object In arrList
            For Each value As Object In row
                Debug.Print(value.GetType.ToString & " : " & value)
            Next
        Next

Output:

    System.String : red
    System.Int32 : 4
    System.String : r
    System.String : blue
    System.Int32 : 5
    System.String : b

*It's generally considered a bad design to do this type of thing with mixed types in an array.  Why do you need this?

A better design would use a generic List containing a custom Class.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.