VB] 如何初始化结构中的第二个数组
VB] How to initialize 2nd array in struct
初始化数组的地方出错
如何使用该数组?
必须是字符的二维数组...
谢谢....
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure ST_TEST
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=360)>
Public 2D_CHAR_ARR()() As Char '//Array In Struct can not be fixed row&col
End Structure
''''''''''''''''''''''''''''''''''''''''
Dim stTest As ST_TEST
ReDim stTest.2D_CHAR_ARR(60)(60) ' //throws System.NullReferenceException
出现空引用是因为您定义的数组不是方形数组,而是数组的数组。要 ReDim
你需要写类似
的东西
ReDim MyArray(60)
For i As Integer = 0 To 60
ReDim MyArray(i)(60)
Next i
如果方阵是你想要的,你应该声明它
Public MyArray(60, 60)
多维数组
Dim matrix = New Integer(4, 4) {{1, 2}, {3, 4}, {5, 6}, {7, 8}}
锯齿状数组
Dim sales()() As Double = New Double(11)() {}
初始化数组的地方出错
如何使用该数组?
必须是字符的二维数组...
谢谢....
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure ST_TEST
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=360)>
Public 2D_CHAR_ARR()() As Char '//Array In Struct can not be fixed row&col
End Structure
''''''''''''''''''''''''''''''''''''''''
Dim stTest As ST_TEST
ReDim stTest.2D_CHAR_ARR(60)(60) ' //throws System.NullReferenceException
出现空引用是因为您定义的数组不是方形数组,而是数组的数组。要 ReDim
你需要写类似
ReDim MyArray(60)
For i As Integer = 0 To 60
ReDim MyArray(i)(60)
Next i
如果方阵是你想要的,你应该声明它
Public MyArray(60, 60)
多维数组
Dim matrix = New Integer(4, 4) {{1, 2}, {3, 4}, {5, 6}, {7, 8}}
锯齿状数组
Dim sales()() As Double = New Double(11)() {}