Array of queues in VB.Net

Probably a very stupid question, but I want to create an array of queues in vb.net - so I can reference each queue with an index:

eg,

commandQueue(1).enqueue("itemtext")

commandQueue(2).enqueue("othertext")

      

where commandQueue (1) refers to a separate queue than commandQueue (2)

I got confused trying to define an array of objects and queue up.

Yes, of course, I can do it with vintage arrays, pointers, etc. by doing manual manipulation, but that seemed much more elegant ...

+1


source to share


1 answer


What's wrong with this solution?

Dim commandQueue As Queue(Of T)()

      

There is nothing "old fashioned" about this solution. However, dynamic memories can sometimes be better suited:



Dim commandQueue As New List(Of Queue(Of T))()

      

In both cases, you need to initialize each queue before using it! In the case of an array, you also need to initialize the array:

' Either directly: '
Dim commandQueue(9) As Queue(Of T)
' or, arguably clearer because the array length is mentioned explicitly: '
Dim commandQueue As Queue(Of T)() = Nothing ' `= Nothing` prevents compiler warning '
Array.Resize(commandQueue, 10)

      

+3


source







All Articles