0

Excuse me,i want to create an array by vb.net How can i do it?

I would like to use a for-loop to finish it.

this is an array:

 [1,2,3,4,5,6,7,8,9,.....,100]
BigBen
  • 46,229
  • 7
  • 24
  • 40
Lewis
  • 19
  • 1
  • 1
    What have you tried already? Also, look up generics like List(of T) and the .ToArray() method. – Phoenix Stoneham Apr 06 '20 at 14:14
  • How important is it that it gives you a static array? A for loop may have any number or iterations, a dynamic array like a List would be easier to get. – laancelot Apr 06 '20 at 14:15

1 Answers1

1

You don't necessarily have to use a For loop since you just want sequential numbers. Here is sort of a one-liner solution:

Dim collection() As Integer = Enumerable.Range(1, 100).ToArray()

Fiddle: Live Demo

Otherwise, if you're limitted to using a For/Next, then create a collection with a set upper-bounds and then loop from 1 to 100:

Dim collection(99) As Integer
For c As Integer = 1 To 100
    collection(c - 1) = c
Next

Fiddle: Live Demo

David
  • 5,877
  • 3
  • 23
  • 40