如何制作无限变量(如Num1,Num2等)?

时间:2013-01-19 04:33:48

标签: vb.net

我正在使用vb 2012 express(用于桌面),我很想知道如何制作无限变量。 例如

Dim Num1 as integer
Dim Num2 as integer

我希望应用程序使用Num3,4,5,6等创建一个新变量。 这可能吗?如果是这样,怎么样?

2 个答案:

答案 0 :(得分:2)

考虑使用和数组或列表:

    Dim Num As New List(Of Integer) 'Create a list of integers
    For i = 0 To Integer.MaxValue 'Add to the list as much as it can hold which is 2147483647 items, it is integer's maximum value.
        Num.Add(0)
    Next

    'OR

    Dim NumArray(Integer.MaxValue) As Integer 'Create an array of integers which holds maximum number of items, again 2147483647 items.

    'Youy may access them both via their indexes:
    Console.WriteLine(Num(0))
    Console.WriteLine(Num(1))
    Console.WriteLine(Num(2))
    'or
    Console.WriteLine(NumArray(0))
    Console.WriteLine(NumArray(1))
    Console.WriteLine(NumArray(2))
    'and so on... 

顺便说一下,Console.WriteLine()在这种情况下将整数转换为字符串。

答案 1 :(得分:0)

这是你需要数组(或者可能是集合类,取决于其他需求)。

类似的东西:

Dim Idx As Integer
Dim Num(10) As Integer

' Now you can use Num(0) thru Num(10) '
For Idx = 0 To 10
    Num(Idx) = 10 - Idx
Next
相关问题