2010年10月10日 星期日

VB.net 類別內有陣列的寫法(宣告,寫入,讀取)

Public Class MainParentCluster
Private _TargetIdentifier As String '目標名稱
Private _ConnectCount As Long '連結之物件數量

Private _aArrary() As Long '陣列,儲存數個數值

Public Property TargetIdentifier() As String '名稱
Get
Return _TargetIdentifier
End Get
Set(ByVal Value As String)
_TargetIdentifier = Value
End Set
End Property
Public Property ConnectCount() As Long '連結之物件數量
Get
Return _ConnectCount
End Get
Set(ByVal Value As Long)
_ConnectCount = Value
End Set
End Property
'屬性為 陣列 的用法
Public Property aArrary() As Long()
Get
Return _aArrary
End Get
Set(ByVal Value As Long())
_aArrary = Value
End Set
End Property
End Class

'寫入 ------------------------------------
Dim MainClusterObj As New List(Of ParentObj_SubCount)
Dim preCluster As String = ""
Dim ccnt As Long = 0
Dim i As Long
Dim k As New List(Of Long)

For i = 1 To 10 '測試寫入10筆資料!
preCluster = "A" & i
ccnt = i * 10
'自訂測試 給予類別內的陣列 3筆資料
k.Add(i)
k.Add(i + 1)
k.Add(i + 2)
MainClusterObj.Add(New ParentObj_SubCount With {.ParentObjName = preCluster, .ChildCount = ccnt, .LineArrary = k.ToArray})
k.Clear()

Next


'讀取 ------------------------------------


Dim PP As ParentObj_SubCount
'Dim PP As MainParentCluster

Dim PPArray As String

For Each PP In MainClusterObj
PPArray = ""
For i = 0 To PP.LineArrary.Length - 1

PPArray &= i & "值=" & PP.LineArrary(i).ToString & ","
Next
Debug.Print(PP.ParentObjName & " " & PP.ChildCount & " " & PPArray)
Next

沒有留言:

張貼留言

追蹤者