StringCollection.CopyTo Method copies StringCollection values to a one-dimensional array
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Public Class SamplesStringCollection
Public Shared Sub Main()
Dim myCol As New StringCollection()
Dim myArr() As [String] = {"RED", "orange", "yellow"}
myCol.AddRange(myArr)
PrintValues(myCol)
Dim myArr2(myCol.Count) As [String]
myCol.CopyTo(myArr2, 0)
Dim i As Integer
For i = 0 To myArr2.Length - 1
Console.WriteLine(" [{0}] {1}", i, myArr2(i))
Next i
End Sub 'Main
Public Shared Sub PrintValues(myCol As IEnumerable)
Dim obj As [Object]
For Each obj In myCol
Console.WriteLine(" {0}", obj)
Next obj
Console.WriteLine()
End Sub
End Class
Related examples in the same category