How can I use the following events/delgates, written in C#, in VB.NET?

我怕爱的太早我们不能终老 提交于 2019-12-02 03:39:15

The += operator is basically subscribing the FeedbackService.OnError function to the Error invocation list. So when the Error event is raised, the OnError method is invoked.

To translate the above code to VB.NET, it would look something like:

// define delelgate/event
Public Delegate Sub OnError(sender As Object, ex As Exception)
Public Event OnError Error

// attach method to event
AddHandler service.Error, service_Error

See How to: Raise and Consume Events for some examples in VB.NET.

AddHandler service.Error, service_Error

I'm not sure on the VB implementation I'm afraid, but the += syntax in C# with respect to delegates, adds a method to the delegates list of methods (invocation list)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!