Complete the code to declare a delegate named Notify.
public delegate void [1]();The delegate named Notify is declared to define the signature for event handlers.
Complete the code to declare an event named OnNotify using the Notify delegate.
public event [1] OnNotify;The event OnNotify is declared using the Notify delegate type.
Fix the error in the code to correctly subscribe a method named HandleNotification to the OnNotify event.
publisher.OnNotify [1]= HandleNotification;The correct operator to subscribe a method to an event is +=.
Fill both blanks to raise the OnNotify event safely.
if (OnNotify [1] null) { OnNotify[2](); }
Check if the event is not null using != and invoke it safely using ?.Invoke().
Fill all three blanks to create a dictionary of subscribers with their names and subscribe them to the event.
var subscribers = new Dictionary<string, Notify>()
{
{"Alice", [1],
{"Bob", [2]
};
foreach (var subscriber in subscribers)
{
publisher.OnNotify [3]= subscriber.Value;
}Subscribers are methods named AliceHandler and BobHandler. They are subscribed to the event using +=.