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

Action delegate type in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Avoid
Bint
Cstring
Dbool
Which of the following is a valid Action delegate declaration?
AAction<int> myFunc;
BFunc<void> myAction;
CFunc<int, string> myAction;
DAction<int, string> myAction;
How many parameters can an Action delegate have at most?
A16
B8
C4
DNo limit
Which delegate type should you use if you want a method that returns a value?
AAction
BEventHandler
CFunc
DPredicate
What is the output of this code? Action<string> print = s => Console.WriteLine(s); print("Hi");
Aprint
BHi
Cs
DNo output
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.