2015-12-22 124 views
0
中初始化第二個數組

初始化數組的地方發生錯誤。如何使用該數組?如何使用數組?VB]如何在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 

回答

1

空引用發生,因爲你的數組作爲您已經定義是不一個正方形數組,但是一組數組。要ReDim它,你需要的,如果一個方陣是你想要什麼,喜歡寫東西

ReDim MyArray(60) 

For i As Integer = 0 To 60 
    ReDim MyArray(i)(60) 
Next i 

,你應該把它聲明

Public MyArray(60, 60) 
+0

儘管基本問題,謝謝你寫的答案。 我很榮幸能夠學習新知識。 非常感謝! 祝您有美好的一天。 –

0

多維數組

Dim matrix = New Integer(4, 4) {{1, 2}, {3, 4}, {5, 6}, {7, 8}} 

鐵血陣列

Dim sales()() As Double = New Double(11)() {} 

Arrays in Visual Basic