开发者

Is it possible to declare a generic event in vb.NET?

I have tried to write:

Event EventName(Of T)()

But Visual Studio tells me开发者_Python百科 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜