question

jidetorres-9680 avatar image
0 Votes"
jidetorres-9680 asked karenpayneoregon edited

How to implement ArrayList in vb.net using console

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]: /answers/storage/attachments/81479-screenshot-2021-03-25-17-01-12-43-5b2419c719731733.jpg

dotnet-visual-basic
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

As Karen pointed out use a List(Of T) rather than an ArrayList if possible.

1 Vote 1 ·
vb2ae avatar image
3 Votes"
vb2ae answered karenpayneoregon edited

You would need at the top of the code file


     Imports System.Collections
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Like I doubt, I am missing imports. Thank you, this line is just what I need.81616-screenshot-2021-03-25-222714.png


1 Vote 1 ·

I just noticed you are using a non-standard compiler, that is likely the reason there is a need for the Import. Same would most likely happen with VS-Code but not in Visual Studio.

In the future you should indicate you are not using Visual Studio or the standard compiler (seems you are working with mono)

1 Vote 1 ·

Interesting, in a standard console project there is zero need for the Import statement as in my VS2019 code sample. Yet if that's what it took, that's all which is important.

81570-f1.png


0 Votes 0 ·
f1.png (8.7 KiB)
karenpayneoregon avatar image
2 Votes"
karenpayneoregon answered jidetorres-9680 commented

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




f1.png (8.6 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I appreciate It, this method will help me in the future, for now, I'll use Imports System.Collections
Thankyou

0 Votes 0 ·