【问题标题】:Array of Queues in VB.NetVB.Net 中的队列数组
【发布时间】:2008-12-06 21:56:34
【问题描述】:

可能是一个非常愚蠢的问题,但我想在 vb.net 中创建一个队列数组 - 所以我可以使用索引来引用每个队列:

例如

commandQueue(1).enqueue("itemtext")

commandQueue(2).enqueue("othertext")

其中 commandQueue(1) 指的是与 commandQueue(2) 不同的队列

我在试图定义一个对象数组并放入队列时很纠结。

是的,我当然可以用老式的数组、指针等来做,手动管理,但这看起来要优雅得多...

【问题讨论】:

    标签: vb.net queue


    【解决方案1】:

    这个解决方案有什么问题?

    Dim commandQueue As Queue(Of T)()
    

    这个解决方案没有什么“过时的”。然而,动态记忆有时可能更适合:

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

    在这两种情况下,您都需要在使用之前初始化每个队列!在数组的情况下,数组也必须被初始化:

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

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2014-10-12
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 2011-07-27
      相关资源
      最近更新 更多