Public Events

  • Thread starter Thread starter Charlie Brown
  • Start date Start date
C

Charlie Brown

What is the advantage of declaring events in #2 over #1. Which one
should be used?

#1
Public Event MyEvent(sender as object, e as eventargs)

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

#2
Public Delegate Sub MyEventHandler(sender as object, e as eventargs)

Public Event MyEvent as MyEventHandler

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub
 
Charlie Brown said:
What is the advantage of declaring events in #2 over #1. Which one
should be used?

#1
Public Event MyEvent(sender as object, e as eventargs)

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

#2
Public Delegate Sub MyEventHandler(sender as object, e as eventargs)

Public Event MyEvent as MyEventHandler

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

#2 allows you to reuse the delegate type for more than one event.
 
Back
Top