Custom Collections in VB.NET 
Author Message
 Custom Collections in VB.NET

It is easy to implement a custom collection in C#, but I
can't figure out how to do it in VB.NET yet. When I begin
to implement the GetEnumerator function below I get the
following error.  There are two examples that get the
same error when compliled.

The error is:
'BasicCollections.Class1' must implement 'Overridable
Overloads Function GetEnumerator() As IEnumerabor' for
interface 'System.Collections.IEnumerable'.

''''''''''''''''''''' Code '''''''''''''''''''''''''
Imports System.Collections

Public Class Class1
    Implements IEnumerable

    Function GetEnumerator() As IEnumerator
    End Function

End Class
''''''''''''''''''' End Code ''''''''''''''''''''''

When I use the function signature as stated in the error
message, I get the same error.

''''''''''''''''''''' Code '''''''''''''''''''''''''
Public Class Class1
    Implements IEnumerable

    Overridable Overloads Function GetEnumerator() As
IEnumerator

    End Function

End Class
''''''''''''''''''' End Code ''''''''''''''''''''''



Fri, 26 Aug 2005 23:59:31 GMT  
 Custom Collections in VB.NET
It's easy in VB.NET too, just totally different.  :)  Here's some slightly
modified code of mine.

Option Strict On
Namespace CollectionClasses
    Public Class MyCollection : Inherits System.Collections.CollectionBase
        ' return the item instance. This is a Default property so it won't
have to be explicitly stated.
        Default Public ReadOnly Property Item(ByVal intIndex As Integer) As
MyItem
            Get
                Return CType(list.Item(intIndex), MyItem)
            End Get
        End Property

        ' add a new member
        Public Sub Add(ByVal objItem As MyItem)
            list.Add(objItem)
        End Sub

        ' remove an existing member
        Public Sub Remove(ByVal intIndex As Integer)
            Try
                list.RemoveAt(intIndex)
            Catch exc As Exception
                Throw New ArgumentOutOfRangeException()
            End Try
        End Sub

    End Class
End Namespace



Quote:
> It is easy to implement a custom collection in C#, but I can't figure out
> how to do it in VB.NET yet. When I begin to implement the GetEnumerator
> function below I get the following error.  There are two examples that
> get the same error when compliled.

> The error is:
> 'BasicCollections.Class1' must implement 'Overridable Overloads Function
> GetEnumerator() As IEnumerabor' for interface
> 'System.Collections.IEnumerable'.

> ''''''''''''''''''''' Code '''''''''''''''''''''''''
> Imports System.Collections

> Public Class Class1
> Implements IEnumerable
> Function GetEnumerator() As IEnumerator
> End Function

> End Class
> ''''''''''''''''''' End Code ''''''''''''''''''''''

> When I use the function signature as stated in the error message, I get
> the same error.

> ''''''''''''''''''''' Code '''''''''''''''''''''''''
> Public Class Class1
> Implements IEnumerable

> Overridable Overloads Function GetEnumerator() As IEnumerator

> End Function

> End Class
> ''''''''''''''''''' End Code ''''''''''''''''''''''

--
Chris J. Breisch, MCSD, MCDBA


Sat, 27 Aug 2005 00:08:29 GMT  
 Custom Collections in VB.NET
Implementation of a method from an interface in VB isn't done by name - you
need to add the implements statement to method declaration:
Public Class Class1
   Implements IEnumerable
   Function GetEnumerator() As IEnumerator Implements
IEnumerable.GetEnumerator
   End Function
End Class

(Just to show what I mean with the implementation not being done by name,
the following will also work:)
Public Class Class1
   Implements IEnumerable
   Function WhoAskedForAnEnumerator() As IEnumerator Implements
IEnumerable.GetEnumerator
   End Function
End Class

Alex
MS VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.

___

Quote:
> It is easy to implement a custom collection in C#, but I
> can't figure out how to do it in VB.NET yet. When I begin
> to implement the GetEnumerator function below I get the
> following error.  There are two examples that get the
> same error when compliled.

> The error is:
> 'BasicCollections.Class1' must implement 'Overridable
> Overloads Function GetEnumerator() As IEnumerabor' for
> interface 'System.Collections.IEnumerable'.

> ''''''''''''''''''''' Code '''''''''''''''''''''''''
> Imports System.Collections

> Public Class Class1
>     Implements IEnumerable

>     Function GetEnumerator() As IEnumerator
>     End Function

> End Class
> ''''''''''''''''''' End Code ''''''''''''''''''''''

> When I use the function signature as stated in the error
> message, I get the same error.

> ''''''''''''''''''''' Code '''''''''''''''''''''''''
> Public Class Class1
>     Implements IEnumerable

>     Overridable Overloads Function GetEnumerator() As
> IEnumerator

>     End Function

> End Class
> ''''''''''''''''''' End Code ''''''''''''''''''''''



Sat, 27 Aug 2005 04:19:06 GMT  
 Custom Collections in VB.NET
I created a collection object by inheriting ICollectionBase
Quote:
>Subject: Custom Collections in VB.NET

>Date: 10/03/03 15:59 GMT Standard Time

>It is easy to implement a custom collection in C#, but I
>can't figure out how to do it in VB.NET yet. When I begin
>to implement the GetEnumerator function below I get the
>following error.  There are two examples that get the
>same error when compliled.

>The error is:
>'BasicCollections.Class1' must implement 'Overridable
>Overloads Function GetEnumerator() As IEnumerabor' for
>interface 'System.Collections.IEnumerable'.

>''''''''''''''''''''' Code '''''''''''''''''''''''''
>Imports System.Collections

>Public Class Class1
>    Implements IEnumerable

>    Function GetEnumerator() As IEnumerator
>    End Function

>End Class
>''''''''''''''''''' End Code ''''''''''''''''''''''

>When I use the function signature as stated in the error
>message, I get the same error.

>''''''''''''''''''''' Code '''''''''''''''''''''''''
>Public Class Class1
>    Implements IEnumerable

>    Overridable Overloads Function GetEnumerator() As
>IEnumerator

>    End Function

>End Class
>''''''''''''''''''' End Code ''''''''''''''''''''''



Sun, 04 Sep 2005 06:59:50 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB.NET Custom Collection (HELP!)

2. ATTN: Microsoft: VS.Net 2003 and Custom Collections

3. VS.NET 2003 and Custom Collections (post 2 - no replies to one)

4. How to Create Custom Wizard (something like c++ Custom Wizard) In VB.Net

5. Passing Form Fields to VB.NET Custom Business Object in an ASP.NET Code Behind Page

6. Serialization of Collection in VB.NET

7. VB.NET collection object references messed up?

8. Collection Classes in VB.NET

9. Build Collection with VB.NET

10. forms collection in vb.net

 

 
Powered by phpBB® Forum Software