【问题标题】:Is there a way to remove an item from a queue?有没有办法从队列中删除一个项目?
【发布时间】:2016-07-03 07:03:54
【问题描述】:

我正在使用Queue(Of T)

我知道,先进先出。

说,我有时想随机取出一些不一定在第一个的T项目。

我该怎么做?

【问题讨论】:

标签: vb.net


【解决方案1】:

恐怕没有直接的方法可以做到这一点。
您可以使用这样的解决方法,但它会损害性能,我不确定它是否会保持顺序正确:

Dim myQueue = New Queue(Of MyType)()
' Populate queue here...
Dim muList = myQueue.ToList()
muList.RemoveAt(1)
myQueue.Clear()
muList.ForEach(Function(item) myQueue.Enqueue(item))

【讨论】:

  • 出于我的目的,我使用哈希集和队列。哈哈哈
  • 相同的区别:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-09
相关资源
最近更新 更多