Queue 类的属性和方法
下表列出了Queue类的一些常用属性-
下表列出了Queue类的一些常用方法--
方法 |
描述 |
Public Overridable Sub Clear |
从队列中删除所有元素。 |
Public Overridable Function Contains (obj As Object) As Boolean |
确定元素是否在队列中。 |
Public Overridable Function Dequeue As Object |
删除并返回队列开始处的对象。 |
Public Overridable Sub Enqueue (obj As Object) |
将一个对象添加到队列的末尾。 |
Public Overridable Function ToArray As Object() |
将队列复制到新阵列。 |
Public Overridable Sub TrimToSize |
将容量设置为队列中元素的实际数量。 |
示例:
Imports System.Collections
Module collections
Sub Main()
Dim q As Queue = New Queue()
q.Enqueue("A")
q.Enqueue("M")
q.Enqueue("G")
q.Enqueue("W")
Console.WriteLine("Current queue: ")
Dim c As Char
For Each c In q
Console.Write(c + " ")
Next c
Console.WriteLine()
q.Enqueue("V")
q.Enqueue("H")
Console.WriteLine("Current queue: ")
For Each c In q
Console.Write(c + " ")
Next c
Console.WriteLine()
Console.WriteLine("Removing some values ")
Dim ch As Char
ch = q.Dequeue()
Console.WriteLine("The removed value: {0}", ch)
ch = q.Dequeue()
Console.WriteLine("The removed value: {0}", ch)
Console.ReadKey()
End Sub
End Module
尝试一下
编译并执行上述代码后,将产生以下结果-
Current queue:
A M G W
Current queue:
A M G W V H
Removing some values
The removed value: A
The removed value: M