Results 1 to 7 of 7

Thread: Return collection as IEnumerator

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425

    Return collection as IEnumerator

    Hi all,

    In my current situation I have two classes;
    1. ClsItem - one is the class with properties (like name and value)
    2. ClsCol - one is the class having a private collection object and storing the items with the type of class 1.

    What I want to do is implement a 'items' property that is used in the for each loops. Now, what I thought was this in the ClsCol;

    VB Code:
    1. Private m_Data As Collection
    2.     Public ReadOnly Property Data() As IEnumerable(Of ClsItem)
    3.         Get
    4.             Return m_Data
    5.         End Get
    6.     End Property

    Using the IEnumerable(Of ClsItem) I though I would be able to do a for each like this;
    VB Code:
    1. Dim col As New ClsCol
    2. 'Add some items...
    3. For Each item As ClsItem In col.Data
    4.     'Do something with 'item'
    5. Next

    However, the compiler says that I can not cast the m_Data as ClsItem in the Items property...

    Can anyone help me out here?

    Thanks.

    P.s. Using VS 2005
    Last edited by BShadow; Dec 7th, 2006 at 05:03 AM. Reason: Adding the VS 2005 info
    "Experience is something you don't get until just after you need it."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width