Itโs just a field, not an event.
The event is actually a couple of methods (for example, how the property works), but a field like events makes it trivial (you can even specify a default value other than zero, which (I assume) is your intention:
public event CustomEventDelegate CustomEvent = delegate { }; ^^^^^ <==== note the addition of "event" here
It looks like this:
private CustomEventDelegate customEvent = delegate { }; public event CustomEventDelegate CustomEvent { add { customEvent += value;} remove { customEvent -= value;} }
I say โalmostโ because field events also include some thread safety code, which is rarely necessary but difficult to explain (and depends on which version of the compiler you are using).
Of course, in my opinion, itโs better not to use this at all and just check the event for null:
var snapshot = EventOrFieldName; if(snapshot != null) snapshot(args);
An example implementation of this interface:
public interface ISlider { event CustomEventDelegate CustomEvent; } public class MyType : ISlider { public event CustomEventDelegate CustomEvent = delegate { }; }
source share