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?✗ Incorrect
The last generic type parameter in a
Func delegate always represents the return type of the method.Which of the following is a valid
Func delegate declaration?✗ Incorrect
Func<int, string, bool> is valid: two input parameters (int, string) and a bool return type. void cannot be used as a return type in Func.What is the maximum number of input parameters a
Func delegate can have?✗ Incorrect
A
Func delegate can have up to 16 input parameters.Which delegate type should you use if your method does not return a value?
✗ Incorrect
Action delegates represent methods that return void (no value).What will this code output?<br>
Func<int, int> square = x => x * x; Console.WriteLine(square(5));
✗ Incorrect
The lambda squares the input. 5 * 5 = 25.
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<int, int, int></code> and a simple lambda.
You got /4 concepts.