當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Queue.ToArray方法代碼示例

本文整理匯總了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
開發者ID:VB.NET開發者,項目名稱:System.Collections,代碼行數:58,代碼來源:Queue.ToArray

輸出:

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
開發者ID:VB程序員,項目名稱:System.Collections,代碼行數:26,代碼來源:Queue.ToArray


注:本文中的System.Collections.Queue.ToArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。