数据结构句柄为数组
Data structure handle as array
我使用数据结构来存储JSON数据
Class node
Friend ReadOnly position As Integer
Friend ReadOnly position_Array As Integer
Public index As Integer = 0
Friend head As String
Friend parent As node
Friend is_array_item As Boolean = False
' Friend attrib As node_val
Friend child_list As New List(Of node_val)
Friend tail As String
Sub New(ByRef a As node, ByRef pos As Integer) ', b As node_val)
parent = a
' attrib = b
position = pos ' a.child_list.Count - 1
End Sub
End Class
dim n 作为新节点
n.child_list(8).val
dim n as new node
n.child_list(8).val
我想将此 class 的对象句柄作为数组
n(8).val
我是怎么做到的
您可以将 Default Property 添加到您的 node
class,这将 return 来自您的 child_list
的项目:
Class node
Friend ReadOnly position As Integer
Friend ReadOnly position_Array As Integer
Public index As Integer = 0
Friend head As String
Friend parent As node
Friend is_array_item As Boolean = False
Friend child_list As New List(Of node)
Friend tail As String
Sub New(ByRef a As node, ByRef pos As Integer)
parent = a
position = pos
End Sub
''' <summary>
''' Gets or sets child node.
''' </summary>
''' <param name="index"></param>
Default Property Child(ByVal index As Integer) As node
Get
If index >= 0 And index < child_list.Count Then
Return child_list.Item(index)
Else
' index is out of bounds
Return Nothing
End If
End Get
Set(value As node)
If index < 0 Then Return
If index < child_list.Count Then
child_list.Item(index) = value
Else
' Add node at end of list
child_list.Add(value)
End If
End Set
End Property
End Class
请注意 Child
属性 上的 setter。列表中的项目应按顺序插入。
我使用数据结构来存储JSON数据
Class node
Friend ReadOnly position As Integer
Friend ReadOnly position_Array As Integer
Public index As Integer = 0
Friend head As String
Friend parent As node
Friend is_array_item As Boolean = False
' Friend attrib As node_val
Friend child_list As New List(Of node_val)
Friend tail As String
Sub New(ByRef a As node, ByRef pos As Integer) ', b As node_val)
parent = a
' attrib = b
position = pos ' a.child_list.Count - 1
End Sub
End Class
dim n 作为新节点 n.child_list(8).val
dim n as new node
n.child_list(8).val
我想将此 class 的对象句柄作为数组
n(8).val
我是怎么做到的
您可以将 Default Property 添加到您的 node
class,这将 return 来自您的 child_list
的项目:
Class node
Friend ReadOnly position As Integer
Friend ReadOnly position_Array As Integer
Public index As Integer = 0
Friend head As String
Friend parent As node
Friend is_array_item As Boolean = False
Friend child_list As New List(Of node)
Friend tail As String
Sub New(ByRef a As node, ByRef pos As Integer)
parent = a
position = pos
End Sub
''' <summary>
''' Gets or sets child node.
''' </summary>
''' <param name="index"></param>
Default Property Child(ByVal index As Integer) As node
Get
If index >= 0 And index < child_list.Count Then
Return child_list.Item(index)
Else
' index is out of bounds
Return Nothing
End If
End Get
Set(value As node)
If index < 0 Then Return
If index < child_list.Count Then
child_list.Item(index) = value
Else
' Add node at end of list
child_list.Add(value)
End If
End Set
End Property
End Class
请注意 Child
属性 上的 setter。列表中的项目应按顺序插入。