Mega Code Archive

 
Categories / VB.Net Tutorial / Collections
 

Use ReDim Preserve to add elements to an array

Public Class Tester     Public Shared Sub Main         Dim growingArray() As String = Nothing         ' ----- Add elements to the array.         For counter As Integer = 0 To 2             ReDim Preserve growingArray(counter)             growingArray(counter) = (counter + 1).ToString         Next counter         ' ----- Display the results.         For Each workText As String In growingArray             Console.WriteLine(workText)         Next workText              End Sub End Class 1 2 3