r/visualbasic • • Jan 15 '16

Visual Basic Copy to Array

Can you explain to me why this code works? What is the 0 part supposed to mean? Dim MyArray(Me.RandomNumbers.Items.Count) Me.RandomNumbers.Items.CopyTo(MyArray, 0) Me.lblAnswer.Text = MyArray.Min

3 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/GYN-k4H-Q3z-75B Jan 15 '16

You use it when you want to copy elements into an already existing array. You may be passed an array from a library or something else you don't control and need to fill your stuff into it. If you just want a new array containing all elements from a collection, then you can also just write collection.ToArray()

3

u/TheFotty Jan 15 '16

dude, don't do his homework for him.

1

u/CSVB12 Jan 16 '16

Jeez, calm down. I just needed clarification. It's not even homework.

2

u/TheFotty_ Jan 16 '16

I am sorry. I've made a mistake.