VB.net中怎么定义初始化一个结构体数组
Public Structure Mcu_Information
Dim MCU_ID As Integer 'MCU ID
Dim MCU_String As String 'MCU string
Dim AP_Start_Addr As Integer 'AP Hex start address
Dim AP_End_Addr As Integer 'AP Hex end address
Dim EEP_Start_Addr As Integer 'EEP Hex start address
Dim EEP_End_Addr As Integer 'EEP Hex start address
End Structure
Public MCU_Information_Table() As Mcu_Information ={New Mcu_Information(&H0, "S54F78", &H8000, &HFFFF, &H1000, &H8000)} 'MCU information
我想建张数据表,但是用这种方式总提示Mcu_Information has no constructor?
C里面很好弄的,VB.net里该怎么弄?
多谢!
--------------------编程问答-------------------- 没有构造函数 --------------------编程问答-------------------- 结构不能声明默认构造函数(没有参数的构造函数)或析构函数。
结构可以声明带参数的构造函数。 --------------------编程问答--------------------
Public Structure Term--------------------编程问答-------------------- 两种方式,偷个懒借用一下楼上的代码
Dim coef As Integer '系数
Dim exp As Integer '指数
Sub New(ByVal c As Integer, ByVal e As Integer)
coef = c
exp = e
End Sub
End Structure
Sub Main()
Dim MCU_Information_Table(2) As Mcu_Information
For i As Integer = 0 To 2
Dim temp As New Mcu_Information
temp.MCU_ID = "001"
temp.MCU_String = "001"
temp.AP_Start_Addr = "001"
temp.AP_End_Addr = "001"
temp.EEP_Start_Addr = "001"
temp.EEP_End_Addr = "001"
MCU_Information_Table(i) = temp
Next
Dim ttt(2) As Term
For i As Integer = 0 To 2
ttt(i) = New Term(1, 2)
Next
End Sub
Public Structure Mcu_Information
Dim MCU_ID As Integer 'MCU ID
Dim MCU_String As String 'MCU string
Dim AP_Start_Addr As Integer 'AP Hex start address
Dim AP_End_Addr As Integer 'AP Hex end address
Dim EEP_Start_Addr As Integer 'EEP Hex start address
Dim EEP_End_Addr As Integer 'EEP Hex start address
End Structure
Public Structure Term
Dim coef As Integer '系数
Dim exp As Integer '指数
Sub New(ByVal c As Integer, ByVal e As Integer)
coef = c
exp = e
End Sub
End Structure
--------------------编程问答--------------------
其实我就想以数组的形式建一张静态的数据表(库),根据数组的索引,load对应的成员值。
能不能直接像C一样在声明的时候就对其初始化?
table(3)={(),()}
第一种方式可是可以,但是对其初始化,得挨个挨个成员的赋值,index多的话代码太长了,而且,不同的index,他们的成员可能是不一样的,还不方便用for循环赋值。
补充:.NET技术 , VB.NET