我定义了一个二维数组和一个维数组:
Dim A2(,) As Decimal = New Decimal(1, 2) {{1, 2, 3}, {4, 5, 6}}
Dim A1(2) As Decimal
现在我想将A1的值设置为A2(0)的值 - 这也是2(实际上是3)十进制的数组。
A1= A2(0) ' To insert {1,2,3} to A1
我怎样才能在vb ??
中写这个我会说我不能使用List,我的代码必须使用这个简单的数组
答案 0 :(得分:0)
使用此代码,答案是:It can't be done
。数组A1
只能包含十进制值,而不能包含十进制值数组。
A1(0) = 123D ' Can hold a decimal value, not an array of decimals.
A1(1) = 345D ' Can hold a decimal value, not an array of decimals.
A1(2) = 854D ' Can hold a decimal value, not an array of decimals.
为此,数组A1
必须声明为数组数组:
Dim A1 As Decimal()() = New Decimal(2)() {}
现在您可以将数组分配给A1
:
A1(0) = {1D, 2D, 3D}
示例强>
Dim A2 As Decimal(,) = New Decimal((2 - 1), (3 - 1)) {{1, 2, 3}, {4, 5, 6}}
Dim A1 As Decimal()() = New Decimal(2 - 1)() {}
For i As Integer = 0 To (2 - 1)
Dim array As Decimal() = New Decimal(3 - 1) {}
For j As Integer = 0 To (3 - 1)
array(j) = A2(i, j)
Next
A1(i) = array
Next
MessageBox.Show(String.Join(Environment.NewLine, (From a As Decimal() In A1 Select String.Join(",", a)).ToArray()))
输出:
1,2,3
4,5,6