Consider two ways to declare events.
Either you declare the event using the explicit add / remove method, or you declare the event without such methods.
In other words, you are declaring an event as follows:
public event EventHandlerType EventName { add {
or declare it as follows:
public event EventHandlerType EventName;
The fact is that in a sense this is one and the same, and in other respects they are completely different.
From the point of view of external code, that is ... code outside the class publishing the event is the same. To subscribe to an event, you call a method. To unsubscribe, you call another method.
The difference is that in the second example above, these methods will be provided by the compiler for you, however, that doesn’t matter how it is. To subscribe to an event, you call a method.
The syntax for this, in C #, however, is the same, you also:
objectInstance.EventName += ...;
or
objectInstance.EventName -= ...;
So, from the “external point of view”, the two methods do not differ at all.
However, there is a difference within the class.
If you try to access the EventName inside the class, you are actually referring to a field that supports the property , but only if you use syntax that does not explicitly declare add / remove .
A typical template is as follows:
public event EventHandlerType EventName; protected void OnEventName() { var evt = EventName; if (evt != null) evt(this, EventArgs.Empty); }
In this case, when you refer to EventName , you are really referring to a field that contains a delegate of type EventHandlerType .
However, if you explicitly declared the add / remove methods, referring to the EventName identifier inside the class, it will be both outside the class, since the compiler cannot guarantee that it knows the field, or any other mechanism in which you save the subscription.