0

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

2 Answers 2

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Despite the basic question, thank you for writing the answers. I am honored to be able to learn new knowledge. Thank you very much! Have a good day.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.