Mega Code Archive

 
Categories / VB.Net / Data Structure
 

The ToArray method is used to create an array and copy the queue elements to it

Imports System Imports System.Collections.Generic Module Example     Sub Main         Dim numbers As New Queue(Of String)         numbers.Enqueue("one")         numbers.Enqueue("two")         numbers.Enqueue("three")         numbers.Enqueue("four")         numbers.Enqueue("five")         ' Create a copy of the queue, using the ToArray method and the         ' constructor that accepts an IEnumerable(Of T).         Dim queueCopy As New Queue(Of String)(numbers.ToArray())         Console.WriteLine(vbLf & "Contents of the first copy:")         For Each number As String In queueCopy             Console.WriteLine(number)         Next     End Sub End Module