当前位置: 动力学知识库 > 问答 > 编程问答 >

vb.net - VB] How to initialize 2nd array in struct

问题描述:

An error occurs in the place to initialize the array.

How Can I Use that array ?

It must be a two-dimensional array of character...

Thank you....

<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

网友答案:

The null reference is occurring because your array as you have defined it isn't a square array but an array of arrays. To ReDim it you need to write something like

ReDim MyArray(60)

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

If a square array is what you wanted, you should declare it

Public MyArray(60, 60)
网友答案:

Multi-dimensional array

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

Jagged array

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

From Arrays in Visual Basic

分享给朋友:
您可能感兴趣的文章:
随机阅读: