VB]如何在struct中初始化第二个数组 [英] VB] How to initialize 2nd array in struct
本文介绍了VB]如何在struct中初始化第二个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。
初始化阵列的地方出错。
怎么样我使用那个数组?
它必须是一个二维数组的字符...
谢谢。
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.
<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
推荐答案
你永远不会初始化数组,这就是为什么redim会抛出异常。我想你不需要锯齿状阵列。试试这个:
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
这篇关于VB]如何在struct中初始化第二个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文