1
votes

What is the difference between these 2 statements?

private static event EventHandler<MyEventArg> MyNewEvent;
private static EventHandler<MyEventArg> MyNewEvent;

They both seem to behave the same. I am using .net 3.5. Are there any other ways to define this so that they are functionally identical?

1

1 Answers

2
votes

The difference is that you can invoke event only from class where it was declared.

Event is like automatic property. For every event compiler creates:

  1. Underlying private delegate.
  2. add public method.
  3. remove public method.

When other class does += it is converted to call to add. Since delegate is private it can't be called from other class, and it is impossible to get/change invocation list freely.