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

Multicast delegates 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 declare a delegate named MyDelegate.

C Sharp (C#)
public delegate void [1]();
Drag options to blanks, or click blank then click option'
AMyDelegate
BAction
CDelegate
DFunc
Attempts:
3 left
💡 Hint
Common Mistakes
Using built-in delegate types like Action or Func instead of declaring a new delegate.
Using an invalid delegate name.
2fill in blank
medium

Complete the code to add method1 to the multicast delegate.

C Sharp (C#)
MyDelegate d = method1; d [1]= method2;
Drag options to blanks, or click blank then click option'
A*=
B+
C+=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of +=.
Using -= which removes a method.
3fill in blank
hard

Fix the error in the code to invoke the multicast delegate safely.

C Sharp (C#)
if ([1] != null) d();
Drag options to blanks, or click blank then click option'
Amethod1
Bd
CMyDelegate
Ddelegate
Attempts:
3 left
💡 Hint
Common Mistakes
Checking a method name instead of the delegate variable.
Not checking for null before invoking.
4fill in blank
hard

Fill both blanks to remove method2 from the multicast delegate and invoke it.

C Sharp (C#)
d [1]= method2; if (d [2] null) d();
Drag options to blanks, or click blank then click option'
A-=
B!=
C==
D+=
Attempts:
3 left
💡 Hint
Common Mistakes
Using += instead of -= to remove a method.
Checking d == null instead of d != null.
5fill in blank
hard

Fill all three blanks to create a multicast delegate, add two methods, and invoke it safely.

C Sharp (C#)
MyDelegate d = method1; d [1]= method2; if (d [2] null) d[3]();
Drag options to blanks, or click blank then click option'
A+=
B!=
C()
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to add methods with +=.
Not checking for null before invoking.
Missing parentheses when calling the delegate.