0

Can somebody help me with arrays. in fact I don't understand the difference between these declarations:

Dim MyArray as integer()={5,3,2}

and

Dim MyArray() as integer={5,3,2}

and

Dim MyArray as array={5,3,2}

I have written a large code some variables are defined by the third approach. Now I need to change the size of my array and add new elements one by one to my array, but

array.resize(MyArray,newsize)

just works on arrays defined by the first and second method. How I can change the size of array defined by the third method. How can I add elements to this type of array one by one?

Thanks a lot

  • possible duplicate of [What is the difference between Dim v As String() and Dim v() As String?](http://stackoverflow.com/questions/533166/what-is-the-difference-between-dim-v-as-string-and-dim-v-as-string) – Asad Saeeduddin Aug 14 '13 at 02:42

1 Answers1

1

Instead of worrying about resizing arrays, you should consider using the List(Of T) data structure, which will automatically grow to the size of the amount of objects you want to store, like this:

Dim MyListOfIntegers As New List(Of Integer)()

Now you can add to the list of integers, like this:

MyListOfIntegers.Add(5)
MyListOfIntegers.Add(3)
MyListOfIntegers.Add(2)
Karl Anderson
  • 34,606
  • 12
  • 65
  • 80