Pokus o strukturu StructureArrayItem v arraylistu StructuresArrayItems Užití :
Dim array_names() As String = {"1st", "2nd", "3rd", "fourth"}
Dim ArrayStructures As New StructuresArrayItems
For Each n As String In array_names
ArrayStructures.Add(New StructuresArrayItems.StructureArrayItem(n))
Next
'For i As Integer = 0 To ArrayStructures.Count - 1
' Debug.Print(ArrayStructures(i).ToString)
'Next
'For Each sai As StructuresArrayItems.StructureArrayItem In ArrayStructures
' Debug.Print(sai.ToString)
'Next
Dim b As Boolean
b = ArrayStructures(ArrayStructures.Count - 1).StartsWithNumber
Debug.Print("Last StructureArrayItem In StructuresArrayItems " _
& IIf(b, "starts", "not starts") & " with number.")
Dim sai_4th As New StructuresArrayItems.StructureArrayItem With {.Name = "4th"}
ArrayStructures(3) = sai_4th
b = ArrayStructures(3).StartsWithNumber
Debug.Print("Last StructureArrayItem In StructuresArrayItems " _
& IIf(b, "starts", "not starts") & " with number.")
StructuresArrayItems a StructureArrayItem :
Public Class StructuresArrayItems
Inherits ArrayList
Private Shared _parent As StructuresArrayItems
Public Sub New()
_parent = Me
End Sub
Default Public Shadows Property Item(ByVal index As Integer) As StructureArrayItem
Get
Return MyBase.Item(index)
End Get
Set(ByVal value As StructureArrayItem)
MyBase.Item(index) = value
End Set
End Property
Public Structure StructureArrayItem
Public Sub New(ByVal value As String)
_name = value
End Sub
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public ReadOnly Property Parent As StructuresArrayItems
Get
Return _parent
End Get
End Property
Public ReadOnly Property Index As Integer
Get
Return _parent.IndexOf(Me)
End Get
End Property
Public Function StartsWithNumber() As Boolean
Return Char.IsNumber(_name, 0)
End Function
Public Overrides Function ToString() As String
Return String.Format("StructureArrayItem([Index:={0} Name:='{1}' StartsWithNumber:={2}]", Me.Index, _name, StartsWithNumber)
End Function
End Structure
End Class
|