Complete the code to declare an event in C#.
public event EventHandler [1];The event name is typically a noun or noun phrase like 'Click'. Here, 'Click' is the correct event name.
Complete the code to subscribe to an event named 'DataReceived'.
someObject.DataReceived [1]= HandlerMethod;In C#, you subscribe to an event using the '+=' operator.
Fix the error in the event invocation code.
if ([1] != null) { [1](this, EventArgs.Empty); }
Before invoking an event, check if it is not null, then call it like a method with parameters.
Fill both blanks to declare and raise a custom event with EventHandler.
public event EventHandler [1]; protected virtual void On[2](EventArgs e) { [1]?.Invoke(this, e); }
The event name and the method name usually share the same base name. The event is 'DataProcessed' and the method is 'OnDataProcessed'.
Fill all three blanks to create a custom event with a delegate and raise it.
public delegate void [1](object sender, EventArgs e); public event [1] [2]; protected virtual void On[2](EventArgs e) { [2]?.Invoke(this, e); }
The delegate is named 'DataChangedHandler', the event uses that delegate type, and the event name is 'DataChanged'. The method raising the event is 'OnDataChanged'.