Recall & Review
beginner
What is an Action delegate in C#?
An Action delegate is a predefined delegate type in C# that represents a method that returns void and can take zero or more input parameters.
Click to reveal answer
beginner
How many parameters can an Action delegate have?
An Action delegate can have from zero up to 16 input parameters, but it always returns void (no return value).
Click to reveal answer
beginner
Write a simple example of an Action delegate that takes no parameters.
Action greet = () => Console.WriteLine("Hello!");
greet(); // Prints "Hello!"
Click to reveal answer
intermediate
What is the difference between
Action and Func delegates?Action delegates always return void, while Func delegates return a value and can have input parameters.Click to reveal answer
beginner
How do you declare an Action delegate that takes two integers and prints their sum?
Action printSum = (a, b) => Console.WriteLine(a + b);
printSum(3, 4); // Prints 7
Click to reveal answer
What does an Action delegate return?
✗ Incorrect
Action delegates always return void, meaning they do not return any value.
Which of the following is a valid Action delegate declaration?
✗ Incorrect
Action is valid because Action can take parameters and returns void.
How many parameters can an Action delegate have at most?
✗ Incorrect
Action delegates can have up to 16 input parameters.
Which delegate type should you use if you want a method that returns a value?
✗ Incorrect
Func delegates return a value, unlike Action which returns void.
What is the output of this code?
Action<string> print = s => Console.WriteLine(s);
print("Hi");
✗ Incorrect
The Action delegate prints the string passed to it, so it outputs "Hi".
Explain what an Action delegate is and how it differs from a Func delegate.
Think about return types and input parameters.
You got /4 concepts.
Write a simple example of an Action delegate that takes two integers and prints their product.
Use Action<int, int> and a lambda that multiplies and prints.
You got /4 concepts.