This is a normal implementation:
public event MyDelegate MyEvent;
And this is explicit implementation:
private MyDelegate eventStorage
public event MyDelegate MyEvent
{
add
{
eventStorage += value;
}
remove
{
eventStorage -= value;
}
}
So, which implementation is more suitable and in which cases should I use each?
Thanks for advice
The two examples are equivalent – the compiler would produce the second version (or similar) when compiling the first.
This is just syntactic sugar – use whichever one you are more comfortable with.
You can think of this as similar to what the compiler does with auto-implemented properties, only the other way around.