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 Click.
button.Click [1]= Button_ClickHandler;To subscribe to an event in C#, use the += operator.
Fix the error in the event handler signature for the Click event.
private void Button_ClickHandler(object [1], EventArgs e) { /* handler code */ }The first parameter of an event handler is conventionally named sender, representing the source of the event.
Fill both blanks to raise an event safely in C#.
EventHandler handler = [1]; if (handler [2] null) handler(this, EventArgs.Empty);
Assign the event to a local variable (here Click) and check if it is not null before invoking it.
Fill all three blanks to declare, subscribe, and raise an event named DataReceived.
public event EventHandler [1]; void Subscribe() { [2] += OnDataReceived; } void Raise() { [3] handler = [2]; if (handler != null) handler(this, EventArgs.Empty); }
The event is named DataReceived. Subscription uses the event name DataReceived. Use EventHandler as the type for the local handler variable.