我有一个具有自定义事件的控件。
目前我像任何其他事件一样定义它
Public Event ContentChanged As EventHandler
但是今天我发现一篇文章他们有完全不同的处理方式
Shared ReadOnly contentChangedKey As New Object()
Public Custom Event ContentChanged As EventHandler
AddHandler(value As EventHandler)
Me.Events.AddHandler(contentChangedKey, value)
End AddHandler
RemoveHandler(value As EventHandler)
Me.Events.RemoveHandler(contentChangedKey, Value)
End RemoveHandler
RaiseEvent(sender As Object, e As EventArgs)
Dim contentChangedDelegate As EventHandler = _
Me.Events(contentChangedKey)
contentChangedDelegate(sender, e)
End RaiseEvent
End Event
第二种方法似乎过于复杂,第一个示例没有做什么?