下表列出了Queue類的一些常用屬性:
屬性 | 描述 |
---|---|
Count | Gets the number of elements contained in the Queue. 獲取隊列中包含的元素數(shù)。 |
下表列出了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. 將隊列復(fù)制到新數(shù)組。 |
6 | Public Overridable Sub TrimToSize Sets the capacity to the actual number of elements in the Queue. 將容量設(shè)置為隊列中實(shí)際的元素數(shù)。 |
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
更多建議: