tags:

views:

532

answers:

1

Probably a very dumb 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've got all tangled up trying to define an object array and put queues in.

Yes of course I can do it with old fashioned arrays, pointers etc, doing the management by hand, but this seemed so much more elegant...

+3  A: 

What's wrong with this solution?

Dim commandQueue As Queue(Of T)()

There's nothing “old fashioned” about this solution. However, dynamic memories might 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, the array has to be initialized as well:

' 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)
Konrad Rudolph