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

Action delegate type 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 an Action delegate that takes no parameters.

C Sharp (C#)
Action [1] = () => Console.WriteLine("Hello World");
Drag options to blanks, or click blank then click option'
APrintMessage
BprintMessage
Cprint_message
Dprintmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or underscore in delegate variable names.
Forgetting to assign a lambda expression.
2fill in blank
medium

Complete the code to declare an Action delegate that takes one integer parameter and prints it.

C Sharp (C#)
Action<int> printNumber = [1] => Console.WriteLine([1]);
Drag options to blanks, or click blank then click option'
Anum
Bnumber
Cx
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the parameter and inside the lambda body.
Using reserved keywords as parameter names.
3fill in blank
hard

Fix the error in the Action delegate declaration that takes two string parameters and prints them.

C Sharp (C#)
Action<string, string> printNames = ([1], lastName) => Console.WriteLine($"First: { [1] }, Last: {lastName}");
Drag options to blanks, or click blank then click option'
Afirst
Bname
CfirstName
Dfname
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name in the lambda that does not match the one in the body.
Using too short or unclear parameter names.
4fill in blank
hard

Fill both blanks to create an Action delegate that takes a string and an int, then prints them formatted.

C Sharp (C#)
Action<string, int> printInfo = ([1], [2]) => Console.WriteLine($"Name: { [1] }, Age: { [2] }");
Drag options to blanks, or click blank then click option'
Aname
Bage
Cyears
Dperson
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching parameter names between declaration and usage.
Using unclear or unrelated names.
5fill in blank
hard

Fill all three blanks to create an Action delegate that takes three parameters and prints a formatted message.

C Sharp (C#)
Action<string, int, bool> printDetails = ([1], [2], [3]) => Console.WriteLine($"Name: { [1] }, Age: { [2] }, Active: { [3] }");
Drag options to blanks, or click blank then click option'
AuserName
BuserAge
CisActive
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names.
Choosing unclear or generic names.