E
Erick
I've created a class called Procs and a collection class called
Processes which uses a hastable object to store the Procs.
Now i want to enumerate with the "For each" to extract all the Procs in
my Processes class. As far as i can tell i need to implement an
IEnuerator method to do this. But how ?
'Procs Class
Public Class Procs
Private _Id As Integer
Private _AppName As String
Private _Owner As String
Private _StartTime As DateTime
Friend Property Id()
Get
Return _Id
End Get
Set(ByVal Value)
_Id = Value
End Set
End Property
Friend Property AppName()
Get
Return _AppName
End Get
Set(ByVal Value)
_AppName = Value
End Set
End Property
Friend Property Owner()
Get
Return _Owner
End Get
Set(ByVal Value)
_Owner = Value
End Set
End Property
Friend Property StartTime()
Get
Return _StartTime
End Get
Set(ByVal Value)
_StartTime = Value
End Set
End Property
End Class
'processes class
Imports System.Collections
Public Class Processes
Private _Processes As New Hashtable
Friend Function Add(ByVal Proc As Procs)
_Processes.Add(Proc.Id, Proc)
End Function
Friend Function Item(ByVal Id As Integer) As Procs
Return _Processes.Item(Id)
End Function
Public Function GetEnumerator() As IEnumerator
Return _Processes.GetEnumerator()
End Function
End Class
' test call from a form load event
Dim y As New Procs
Dim v As New Procs
Dim z As New Processes
y.Id = 1
y.AppName = "hello"
v.Id = 2
v.AppName = 2
z.Add(y)
z.Add(v)
Dim q As Procs
For Each q In z
MsgBox(q.Id + " " + q.AppName)
Next
The for each loop won't work because Ienumerate has not been
implemented. But I can't find the correct code to do this. Can some one
fill in the code ?
I'm using .net 1.1
Erick
Processes which uses a hastable object to store the Procs.
Now i want to enumerate with the "For each" to extract all the Procs in
my Processes class. As far as i can tell i need to implement an
IEnuerator method to do this. But how ?
'Procs Class
Public Class Procs
Private _Id As Integer
Private _AppName As String
Private _Owner As String
Private _StartTime As DateTime
Friend Property Id()
Get
Return _Id
End Get
Set(ByVal Value)
_Id = Value
End Set
End Property
Friend Property AppName()
Get
Return _AppName
End Get
Set(ByVal Value)
_AppName = Value
End Set
End Property
Friend Property Owner()
Get
Return _Owner
End Get
Set(ByVal Value)
_Owner = Value
End Set
End Property
Friend Property StartTime()
Get
Return _StartTime
End Get
Set(ByVal Value)
_StartTime = Value
End Set
End Property
End Class
'processes class
Imports System.Collections
Public Class Processes
Private _Processes As New Hashtable
Friend Function Add(ByVal Proc As Procs)
_Processes.Add(Proc.Id, Proc)
End Function
Friend Function Item(ByVal Id As Integer) As Procs
Return _Processes.Item(Id)
End Function
Public Function GetEnumerator() As IEnumerator
Return _Processes.GetEnumerator()
End Function
End Class
' test call from a form load event
Dim y As New Procs
Dim v As New Procs
Dim z As New Processes
y.Id = 1
y.AppName = "hello"
v.Id = 2
v.AppName = 2
z.Add(y)
z.Add(v)
Dim q As Procs
For Each q In z
MsgBox(q.Id + " " + q.AppName)
Next
The for each loop won't work because Ienumerate has not been
implemented. But I can't find the correct code to do this. Can some one
fill in the code ?
I'm using .net 1.1
Erick