队列类的属性和方法
下表列出了Queue类的一些常用属性:
属性 | 描述 |
---|---|
Count | Gets the number of elements contained in the Queue. 获取队列中包含的元素数。 |
下表列出了Queue类的一些常用方法:
S.N | 方法名称和用途 |
---|---|
1 | Public Overridable Sub Clear Removes all elements from the Queue. 从队列中删除所有元素。 |
2 | Public Overridable Function Contains (obj As Object) As Boolean Determines whether an element is in the Queue. 确定元素是否在队列中。 |
3 | Public Overridable Function Dequeue As Object Removes and returns the object at the beginning of the Queue. 删除并返回队列开头的对象。 |
4 | Public Overridable Sub Enqueue (obj As Object) Adds an object to the end of the Queue. 将对象添加到队列的末尾。 |
5 | Public Overridable Function ToArray As Object() Copies the Queue to a new array. 将队列复制到新数组。 |
6 | Public Overridable Sub TrimToSize Sets the capacity to the actual number of elements in the Queue. 将容量设置为队列中实际的元素数。 |
示例:
- 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
转载本站内容时,请务必注明来自W3xue,违者必究。