Search code examples
vb.netfor-loopuipathuipath-studio

how to create a list by forloop in vb.net?


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]

Solution

  • 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