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

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

Choose your learning style9 modes available
Recall & Review
beginner
What is a Func delegate in C#?
A Func delegate is a predefined delegate type in C# that represents a method that returns a value and can take zero or more input parameters.
Click to reveal answer
beginner
How many parameters can a Func delegate have?
A Func delegate can have from zero up to 16 input parameters, with the last generic type parameter always representing the return type.
Click to reveal answer
intermediate
Explain the generic type parameters in Func<T1, T2, TResult>.
In Func<T1, T2, TResult>, T1 and T2 are input parameter types, and TResult is the return type of the method the delegate points to.
Click to reveal answer
beginner
What is the difference between Action and Func delegates?
Action delegates represent methods that return void (no value), while Func delegates represent methods that return a value.
Click to reveal answer
beginner
Show a simple example of a Func<int, int, int> delegate usage.
Example:<br>
Func<int, int, int> add = (x, y) => x + y;
int result = add(3, 4); // result is 7
Click to reveal answer
What does the last generic type parameter in a Func delegate represent?
AThe return type
BThe first input parameter
CThe number of parameters
DThe delegate name
Which of the following is a valid Func delegate declaration?
AFunc&lt;int, string, bool&gt;
BFunc&lt;void, int&gt;
CFunc&lt;void&gt;
DFunc&lt;int, int, void&gt;
What is the maximum number of input parameters a Func delegate can have?
A8
B10
CNo limit
D16
Which delegate type should you use if your method does not return a value?
AFunc
BAction
CPredicate
DEventHandler
What will this code output?<br>
Func<int, int> square = x => x * x;
Console.WriteLine(square(5));
A5
B10
C25
DError
Describe what a Func delegate is and how it differs from an Action delegate.
Think about whether the method returns a value or not.
You got /3 concepts.
    Explain how you would declare and use a Func delegate that takes two integers and returns their sum.
    Use <code>Func&lt;int, int, int&gt;</code> and a simple lambda.
    You got /4 concepts.