你不能只用 「對象」 這一點。你需要建立自己的類:
Public Class File
Public Property FileID As Integer
Public Property FileName As String
Public Sub New()
End Sub
Public Sub New(ByVal FileName As String, ByVal FileID As Integer)
Me.FileID = FileID
Me.FileName = FileName
End Sub
End Class
,然後建立你的隊列是這樣的:
Private QueueList As New ArrayList()
Public Sub Queue(ByVal FileName As String, ByVal FileID As Integer)
QueueList.Add(New File(FileName, FileID))
End Sub
Public Sub Queue(ByVal FileObj As File)
QueueList.Add(FileObj)
End Sub
,或者甚至更好,使用泛型:在
Public QueueList As New List(Of File)()
Public Sub Queue(ByVal FileName As String, ByVal FileID As Integer)
QueueList.Add(New File(FileName, FileID))
End Sub
Public Sub Queue(ByVal FileObj As File)
QueueList.Add(FileObj)
End Sub
然後,循環列表:
For Each item As File In QueueList
'Console.WriteLine(item.FileID & vbTab & item.FileName)
Next item
爲什麼使用arraylist?使用列表進行這項工作。 –