-2

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

Dim Num1 as integer
Dim Num2 as integer

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

4

2 回答 2

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()在这种情况下将整数转换为字符串。

于 2013-01-19T04:46:21.690 回答
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
于 2013-01-19T04:37:52.557 回答