In VB6 you can create your own enumerators by creating a function like this:
function Enumerator() as IUNKnown
Enumerator = col.[_NewEnum]
end function
how do I do this in VB.NET?
Printable View
In VB6 you can create your own enumerators by creating a function like this:
function Enumerator() as IUNKnown
Enumerator = col.[_NewEnum]
end function
how do I do this in VB.NET?
Ah, this is where it becomes a little more convoluted. Have a look at http://peisker.de/index.html?http://...e/vb/lists.htm
You mean like this?Code:Friend Enum myEnums
value1
value2
value3
End Enum
no I don't mean creating those enumerators. what i am talking about is creating the ability to enumerate my own classes, like:
dim ChildClass as Child
for each ChildClass In MyOwnClass
...
next
you can just create a collection of objects from your class can't you?
how?
i don't know if this is wot you mean?Code:
Dim myChild1 As New Child()
Dim myChild2 As New Child()
Dim myCollection As New System.Collections.ArrayList()
myCollection.Add(myChild1)
myCollection.Add(myChild2)
Dim tempChild As Child
For Each tempChild In myCollection
MsgBox(tempChild.name)
Next
Public Class Child
Public name As String = "Nick"
End Class
Hope it helps
Nick
no that's not what i mean. i will give you an example in Vb6 of what I want to do:
Vb6:
VB Code:
Class Test Private p_Collection as Collection Sub Add(o) p_Collection.Add(o) End Sub Public Property Test() As IUnknown Test = p_Collection.[_NewEnum] End Property End Class Public Class TestChild Public Var1 As String End Class Form1: Dim X As New Test Dim Child As New TestChild X.Add(Child) ' This is what I want to do in .NET ' using my own classes For Each Child In Test Msgbox Child.Var1 Next
And just to make this even more clear:
I don't want the solution "Why don't you just make the collection public and access it during the For..Each instead of your class..."
go to the original link up the top:
http://peisker.de/index.html?http://...e/vb/lists.htm
there is a bit on the second third of the article that should help
Nick
isn't this a matter of implementing the IEnumerable interface?
As far as I recall this interface must be implemented if you want to do a
for each A as B in C
/Henrik
isn't this a matter of implementing the IEnumerable interface?
As far as I recall this interface must be implemented if you want to do a
for each A as B in C
/Henrik
maybe. i dont know. can you give me an example?
Perhaps you should read the content on the link I posted :rolleyes:Quote:
Originally posted by danielkw
maybe. i dont know. can you give me an example?