vb.net 如何在结构体内设定定长数组

2024年11月16日 00:33
有2个网友回答
网友(1):

结构体无法初始化值,你可以用类实现,或者写一个构造函数,把值传进去。
Public Structure wheelmodel
Public ID As Short
Public swapway() As Short
Public start As Short

Public Sub New(ByVal Size As UShort) 'Size就是传入的数组的大小
swapway = New Short(Size) {}
End Sub

End Structure
调用的时候:
Dim x As wheelmodel = New wheelmodel(10)

网友(2):

Structure Book
Public Chapter() As Integer
End Structure