0
0
C Sharp (C#)programming~10 mins

Event unsubscription and memory in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to unsubscribe from the event.

C Sharp (C#)
publisher.SomeEvent -= [1];
Drag options to blanks, or click blank then click option'
ASubscribeMethod
BHandlerMethod
CAddHandler
DOnEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than the one used to subscribe.
Trying to unsubscribe with += instead of -=.
2fill in blank
medium

Complete the code to subscribe to the event with a method named OnDataReceived.

C Sharp (C#)
publisher.SomeEvent [1]= OnDataReceived;
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using -= instead of += to subscribe.
Using * or / operators which are invalid here.
3fill in blank
hard

Fix the error in unsubscribing the event handler named HandleEvent.

C Sharp (C#)
publisher.SomeEvent [1]= HandleEvent;
Drag options to blanks, or click blank then click option'
A+
B*
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using += instead of -= when unsubscribing.
Using invalid operators like * or /.
4fill in blank
hard

Fill both blanks to unsubscribe the event handler and avoid memory leaks.

C Sharp (C#)
publisher.[1] [2]= HandlerMethod;
Drag options to blanks, or click blank then click option'
ASomeEvent
B+
C-
DOtherEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Unsubscribing from the wrong event.
Using += instead of -= to unsubscribe.
5fill in blank
hard

Fill all three blanks to subscribe and then unsubscribe the event handler properly.

C Sharp (C#)
publisher.[1] [2]= Handler;
// Later in code
publisher.[1] [3]= Handler;
Drag options to blanks, or click blank then click option'
ASomeEvent
B+
C-
DOtherEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Using different event names for subscribe and unsubscribe.
Using the wrong operator for unsubscribe.