我需要在一维数组中存储一些结构体的二维数组,即:
Public Structure CodeBlock
Public R As Integer
Public C As Integer
Public text_tx As String
Public text_bx As String
Public selected As Boolean
End Structure
Public code(nrows, ncols) As CodeBlock
Public history(5) As List(Of code) '<-- the problem
它告诉你“类型代码未定义”,所以你需要做的就是为Code创建一个类。
也许你的意思是这样的:
Public history As List(Of Code)
Public Structure CodeBlock
Public R As Integer
Public C As Integer
Public text_tx As String
Public text_bx As String
Public selected As Boolean
End Structure
Public Class Code
Public Property Stuff As CodeBlock(,)
Public Sub New()
' Empty constructor
End Sub
Public Sub New(nRows As Integer, nCols As Integer)
Stuff = New CodeBlock(nRows - 1, nCols - 1) {}
End Sub
End Class
Sub Main()
Dim cb = New Code(1, 2)
Dim c = New CodeBlock With {.R = 1, .C = 2, .text_tx = "A", .text_bx = "B", .selected = False}
cb.Stuff(0, 0) = c
history = New List(Of Code)
history.Add(cb)
End Sub