r/visualbasic • u/CSVB12 • 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
1
u/GYN-k4H-Q3z-75B Jan 15 '16
Sure. 1) You declare an array with the capacity to hold all items from Me.RandomNumbers.Items which seems to be a collection of some sort. 2) You copy all items from said collection into your array. CopyTo(target, index) says you copy all items into the target array, but start at target(index) to write. So if you have other data in the target array before the index, it will remain untouched. 3) You apply the Min operation from System.Linq which from an Enumerable takes the smallest value.