Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.

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.

VB
<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
Posted
Updated 22-Dec-15 2:09am
v4
Comments
Tomas Takac 22-Dec-15 8:19am    
What you have there is a jagged array[^].

1 solution

You never initialize the array, that's why redim will throw and exception. And i guess you don't need the jagged array. try this:
VB
Public Structure ST_TEST
    Public _2D_CHAR_ARR(,) As Char '2D array
End Structure

Dim stTest As ST_TEST
stTest._2D_CHAR_ARR = New Char(60, 60) {} ' here you create the array
 
Share this answer
 
Comments
Member 11153736 22-Dec-15 19:18pm    
Despite the basic question, thank you for writing the answers.
Thank you very much!
Have a good day.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900