0

This is more theoretical question then practical, practically I don't have any performance issue.

I'm trying to figure out how does eventד work (and to deduce if there is a performance penalty for using them instead calling a function).

Is an event is just a class that holds a list of pointers to the function that signed up for the event or there is more behind it ?

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
OopsUser
  • 4,642
  • 7
  • 46
  • 71
  • I think your question is answered in this thread: http://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp – bas Mar 31 '13 at 19:39

1 Answers1

1

When an event is raised, a multicast delegate (that essentially gets a new event handler attached to it for every .SomeEvent += MySomeEventHandler that is done on that type instance - it really gets a new delegate list assigned at every +=, but skip that for now) will execute each attached handler. So in every case where more than one event handler is attached, more than one method call will be done. For really low level details, just look at the emitted IL for an event raise situation and compare it to what it looks like when you change the event to a regular callback.

Johann Gerell
  • 24,991
  • 10
  • 72
  • 122