本文整理汇总了VB.NET中System.Collections.Queue.ToArray方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Queue.ToArray方法的具体用法?VB.NET Queue.ToArray怎么用?VB.NET Queue.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.ToArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.Collections
Public Class SamplesQueue
Public Shared Sub Main()
' Creates and initializes the source Queue.
Dim mySourceQ As New Queue()
mySourceQ.Enqueue("three")
mySourceQ.Enqueue("napping")
mySourceQ.Enqueue("cats")
mySourceQ.Enqueue("in")
mySourceQ.Enqueue("the")
mySourceQ.Enqueue("barn")
' Creates and initializes the one-dimensional target Array.
Dim myTargetArray As Array = Array.CreateInstance(GetType(String), 15)
myTargetArray.SetValue("The", 0)
myTargetArray.SetValue("quick", 1)
myTargetArray.SetValue("brown", 2)
myTargetArray.SetValue("fox", 3)
myTargetArray.SetValue("jumps", 4)
myTargetArray.SetValue("over", 5)
myTargetArray.SetValue("the", 6)
myTargetArray.SetValue("lazy", 7)
myTargetArray.SetValue("dog", 8)
' Displays the values of the target Array.
Console.WriteLine("The target Array contains the " & _
"following (before and after copying):")
PrintValues(myTargetArray, " "c)
' Copies the entire source Queue to the target Array, starting
' at index 6.
mySourceQ.CopyTo(myTargetArray, 6)
' Displays the values of the target Array.
PrintValues(myTargetArray, " "c)
' Copies the entire source Queue to a new standard array.
Dim myStandardArray As Object() = mySourceQ.ToArray()
' Displays the values of the new standard array.
Console.WriteLine("The new standard array contains the following:")
PrintValues(myStandardArray, " "c)
End Sub
Public Shared Sub PrintValues(myArr As Array, mySeparator As Char)
Dim myObj As [Object]
For Each myObj In myArr
Console.Write("{0}{1}", mySeparator, myObj)
Next myObj
Console.WriteLine()
End Sub
End Class
输出:
The target Array contains the following (before and after copying): The quick brown fox jumps over the lazy dog The quick brown fox jumps over three napping cats in the barn The new standard array contains the following: three napping cats in the barn
示例2: MainClass
' 导入命名空间
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim m_Queue As New Queue
m_Queue.Enqueue("Text")
m_Queue.Enqueue("Text")
m_Queue.Enqueue("Text")
Dim txt As String = DirectCast(m_Queue.Dequeue(), String)
Console.WriteLine(txt)
For Each str As String In m_Queue.ToArray()
Console.WriteLine(str)
Next str
Console.WriteLine(m_Queue.Count )
End Sub
End Class