How to implement ArrayList in vb.net using console

ji detorres 26 Reputation points
2021-03-25T09:28:26.417+00:00

Dim allOrder As ArrayList = New ArrayList() is seamlessly working on my desktop visual studio. But in mobile Dcoder app or any vb.net compiler it says the error! Please somebody help me how to use collections on vb console in mobile compiler. [81479-screenshot-2021-03-25-17-01-12-43-5b2419c719731733.jpg][1] [1]: /api/attachments/81479-screenshot-2021-03-25-17-01-12-43-5b2419c719731733.jpg?platform=QnA

Developer technologies VB
{count} votes

Accepted answer
  1. Ken Tucker 5,861 Reputation points
    2021-03-25T10:45:49.18+00:00

    You would need at the top of the code file

        Imports System.Collections
    
    3 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-03-25T11:10:34.18+00:00

    I would recommend using a List(Of T) rather than an ArrayList. No matter the following example is .NET Framework 4.8 with the standard references which if missing in the Docker container need to have them available.

    81534-f1.png

    In the code below you can use conventional methods to add items while I hard coded via the from clause.

    Module Module1  
      
        Sub Main()  
            Console.WriteLine("List")  
            For Each item As String In ListExample()  
                Console.WriteLine(item)  
            Next  
      
            Console.WriteLine()  
      
            Console.WriteLine("ArrayList")  
            For Each aItem As Object In ArrayListExample()  
                Console.WriteLine(aItem)  
            Next  
      
            Console.ReadLine()  
      
        End Sub  
      
        Function ListExample() As List(Of String)  
            Return New List(Of String) From {"Karen", "Anne", "Mike"}  
        End Function  
        Function ArrayListExample() As ArrayList  
            Return New ArrayList From {"Karen", "Anne", "Mike"}  
        End Function  
      
    End Module  
      
    
    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.