views:

15

answers:

1

I have tried to write:

Event EventName(Of T)()

But Visual Studio tells me that "Type parameters cannot be specified on this declaration."

Is such a declaration possible or will I have to put T as a regular argument?

+1  A: 

The Event keyword is similar to declaring a field within your class. You wouldn't expect to find:

Private i as GenericClass(Of T)

inside a class that isn't already generic.

You can declare a Delegate with a generic type:

Public Delegate Sub Blah(Of T)()

But then you'd declare your event to be of a concrete type:

Public Event EventName As Blah(Of Int16)

Or if your class was generic, you'd then be able to declare the event as generic too:

Public Delegate Sub Blah(Of T)()


Public Class Referral(Of U)


    Public Event EventName As Blah(Of U)

End Class

Of course, all of these empty argument lists look rather suspect also. We may do better if you can provide more code/more explanation of what you're trying to do.

Damien_The_Unbeliever
I provided an empty argument list because I wanted to ask purely about the syntax. I thought that an `Event` declaration would be similar to `Function`, where you can declare a generic argument even if the class is not generic itself. Thank you for the clarification.
jhominal