Click here to Skip to main content
14,661,076 members
Rate this:
Please Sign up or sign in to vote.
See more:

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

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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:
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
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100