You have to use a Generic Method:

Function Count(Of T)(Col As PersonCollection(Of T)) As Integer

(or a 'non-generic' method in a generic class (Of T)).

I believe this sort of function can use type inference in 2005
sometimes, so you don't need to explicitly say:

Count(Of Employee)(Employees)

but just

Count(Employees)

when Employees is PersonCollection(Of Employee) or EmployeeCollection,
but I haven't checked that.

For each distinct T, X(Of T) is a separate, unrelated type. To
simplify routines like this that /don't/ need the generic type, have
the generic type implement a non-generic interface.

Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)

On 21/8/07, Jeff Paulsen <[EMAIL PROTECTED]> wrote:
> For "MyCollection", please read "PersonCollection". Thank you.
>
> > -----Original Message-----
> > From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> > [EMAIL PROTECTED] On Behalf Of Jeff Paulsen
> > Sent: Monday, August 20, 2007 5:17 PM
> > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
> > Subject: [ADVANCED-DOTNET] Generics as parameters? syntax question
> >
> > I have classes like this:
> >
> > Class Customer
> >   Inherits Person
> > Class Employee
> >   Inherits Person
> >
> > Class PersonCollection(Of T as {Person, New})
> >
> > Class EmployeeCollection
> >   Inherits MyCollection(of Employee)
> > Class CustomerCollection
> >   Inherits MyCollection(of Customer)
> >
> > Now I want to have a function that can operate on any MyCollection.
> > How can
> > I declare that?
> >
> > Thanks in advance,
> >
> > Jeff Paulsen

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to