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

Delegate declaration and instantiation 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 that takes an int parameter.

C Sharp (C#)
public delegate [1] MyDelegate(int number);
Drag options to blanks, or click blank then click option'
Astring
Bvoid
Cint
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using a return type other than void when the method should not return anything.
2fill in blank
medium

Complete the code to instantiate the delegate with a method named PrintNumber.

C Sharp (C#)
MyDelegate del = new MyDelegate([1]);
Drag options to blanks, or click blank then click option'
APrintNumber
BPrint
CShowNumber
DDisplay
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist or does not match the delegate signature.
3fill in blank
hard

Fix the error in the delegate instantiation by completing the code.

C Sharp (C#)
MyDelegate del = [1] (PrintNumber);
Drag options to blanks, or click blank then click option'
Adelegate
Bnew delegate
Cnew MyDelegate
DMyDelegate
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the 'new' keyword or using incorrect keywords.
4fill in blank
hard

Fill both blanks to declare a delegate named Calculator that returns an int and takes two int parameters.

C Sharp (C#)
public delegate [1] Calculator([2] a, int b);
Drag options to blanks, or click blank then click option'
Aint
Bstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types for parameters or return type that don't match the requirement.
5fill in blank
hard

Fill all three blanks to instantiate a delegate named Calculator with a method named Add and invoke it with arguments 5 and 10.

C Sharp (C#)
Calculator calc = [1]([2]);
int result = calc([3], 10);
Drag options to blanks, or click blank then click option'
Anew Calculator
BAdd
C5
DCalculate
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting 'new' keyword, using wrong method name, or wrong argument values.