本文整理匯總了VB.NET中System.Collections.Queue.Peek方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Queue.Peek方法的具體用法?VB.NET Queue.Peek怎麽用?VB.NET Queue.Peek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Peek方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: SamplesQueue
' 導入命名空間
Imports System.Collections
Public Class SamplesQueue
Public Shared Sub Main()
' Creates and initializes a new Queue.
Dim myQ As New Queue()
myQ.Enqueue("The")
myQ.Enqueue("quick")
myQ.Enqueue("brown")
myQ.Enqueue("fox")
' Displays the Queue.
Console.Write("Queue values:")
PrintValues(myQ)
' Removes an element from the Queue.
Console.WriteLine("(Dequeue) {0}", myQ.Dequeue())
' Displays the Queue.
Console.Write("Queue values:")
PrintValues(myQ)
' Removes another element from the Queue.
Console.WriteLine("(Dequeue) {0}", myQ.Dequeue())
' Displays the Queue.
Console.Write("Queue values:")
PrintValues(myQ)
' Views the first element in the Queue but does not remove it.
Console.WriteLine("(Peek) {0}", myQ.Peek())
' Displays the Queue.
Console.Write("Queue values:")
PrintValues(myQ)
End Sub
Public Shared Sub PrintValues(myCollection As IEnumerable)
Dim obj As [Object]
For Each obj In myCollection
Console.Write(" {0}", obj)
Next obj
Console.WriteLine()
End Sub
End Class
輸出:
Queue values: The quick brown fox (Dequeue) The Queue values: quick brown fox (Dequeue) quick Queue values: brown fox (Peek) brown Queue values: brown fox
示例2: MainClass
' 導入命名空間
Imports System
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim intQueue As New Queue( )
Dim i As Integer
For i = 0 To 4
intQueue.Enqueue((i * 5))
Next i
Console.WriteLine("intQueue values:")
DisplayValues(intQueue)
Console.WriteLine("(Dequeue) {0}", intQueue.Dequeue( ))
Console.WriteLine("intQueue values:")
DisplayValues(intQueue)
Console.WriteLine("(Dequeue) {0}", intQueue.Dequeue( ))
Console.WriteLine("intQueue values:")
DisplayValues(intQueue)
Console.WriteLine("(Peek) {0}", intQueue.Peek( ))
Console.WriteLine("intQueue values:")
DisplayValues(intQueue)
End Sub
Public Shared Sub DisplayValues(ByVal myCollection As IEnumerable)
Dim myEnumerator As IEnumerator = myCollection.GetEnumerator( )
While myEnumerator.MoveNext( )
Console.WriteLine("{0} ", myEnumerator.Current)
End While
Console.WriteLine( )
End Sub
End Class