How to put all elements of a String array into Queue(Of String)?
I want to put all elements of a St开发者_如何学运维ring array into a Queue(Of String). I have following code which using For...Each to put string into Queue(Of String):
Dim Files() As String = OpenFileDialog1.FileNames
'OpenFileDialog1 is an instance of OpenFileDialog control
Dim PendingFiles As New Queue(Of String)
For Each x1 As String In Files
PendingFiles.Enqueue(x1)
Next
My question: Is that possible to do it (i.e. put string array into Queue(Of String)) without using For...Each?
Use the constructor of Queue<T>
that takes an IEnumerable<T>
.
Dim PendingFiles As New Queue(Of String)(Files)
精彩评论