将整数变量分配给整数变量并更改名称dynamic

时间:2017-08-02 00:23:39

标签: vb.net

Dim LastNumber as Integer = 1
Dim num_0() as Integer = {1, 2, 3, 4, 5}
Dim num_1() as Integer = {6, 7, 8, 9, 10}
Dim num_2() as Integer = {20, 21, 14, 36, 0}
Dim y() As Integer

y(0) = num_0(2)

当我使用此代码时,它会完美执行

但问题是我想改变" 0"在num_0(2) 我什么时候......

y(0) = num_ & LastNumber & (2)  

这不起作用 要么     y(0)=(" num _"& LastNumber&"(2)") 这给了我一个错误,即将字符串转换为整数是不可能的

我的问题是如何更换" 0"在num_0(2)中使用LastNumber整数变量...所以它读取" 8"数组之外的num_1(2)

1 个答案:

答案 0 :(得分:0)

您可以使用multidimensional array(AKA矩形阵列):

Dim num As Integer(,) = { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {20, 21, 14, 36, 0} }

y(0) = num(LastNumber, 2)

jagged array(数组数组):

Dim num As Integer()() = { ({1, 2, 3, 4, 5}), ({6, 7, 8, 9, 10}), ({20, 21, 14, 36, 0}) }

y(0) = num(LastNumber)(2)