rmatthew Posted March 5, 2006 Posted March 5, 2006 I have the following strongly typed class... I would like to use a for... each loop to iterate through collections.... Is that possible. Public Class Tags Inherits CollectionBase Default Public Property item(ByVal index As Integer) As Tag Get Return CType(List.Item(index), Tag) End Get Set(ByVal value As Tag) List.Item(index) = value End Set End Property Public Function Add(ByVal item As Tag) As Integer Return List.Add(item) End Function End Class Quote
Leaders snarfblam Posted March 5, 2006 Leaders Posted March 5, 2006 For an object to be enumerable (meaning you can use for each), you need to create an enumerator class that implements IEnumerator, and the enumerable class needs to implement the IEnumerable interface to return the enumerator. That probably sounds like a headache, but I believe that the CollectionBase has already implemented the IEnumerable interface. Have you tried using your Tags class in a For Each loop? Quote [sIGPIC]e[/sIGPIC]
rmatthew Posted March 5, 2006 Author Posted March 5, 2006 Back and forth Yes, did try - I have a class that does one but not the other I had one that used the inumerable and would indeed work in a for each loop, but it was based on a position variable and an array of objects.... Now that I have the strongly typed class, I end up with no array/position and am not familiar enough with the list that I get to implement the other. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.