Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted
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?
[sIGPIC]e[/sIGPIC]
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...