Challenge - 5 Problems
Func Delegate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Func delegate example?
Consider the following C# code using a Func delegate. What will be printed to the console?
C Sharp (C#)
Func<int, int, int> multiply = (x, y) => x * y; Console.WriteLine(multiply(3, 4));
Attempts:
2 left
💡 Hint
Func delegates can take parameters and return a value. Here it multiplies two integers.
✗ Incorrect
The Func delegate takes two integers and returns their product. multiply(3,4) returns 12.
❓ Predict Output
intermediate2:00remaining
What is the output of this Func with no parameters?
Look at this C# code using a Func delegate with no parameters. What will it print?
C Sharp (C#)
Func<string> greet = () => "Hello World!";
Console.WriteLine(greet());Attempts:
2 left
💡 Hint
Func can have zero parameters and return a value.
✗ Incorrect
The Func delegate here takes no parameters and returns the string "Hello World!". Calling greet() prints that string.
🔧 Debug
advanced2:00remaining
What error does this Func delegate code produce?
Examine this C# code snippet. What error will it cause when compiled?
C Sharp (C#)
Func<int, int> square = x => x * x; int result = square();
Attempts:
2 left
💡 Hint
Check how many arguments the Func delegate expects.
✗ Incorrect
The Func delegate expects one integer argument. Calling square() with no arguments causes a compile-time error.
🧠 Conceptual
advanced2:00remaining
How many parameters can a Func delegate have at most?
In C#, what is the maximum number of input parameters a Func delegate can have?
Attempts:
2 left
💡 Hint
Check the official Microsoft documentation for Func delegates.
✗ Incorrect
Func delegates can have up to 16 input parameters, with the last type parameter being the return type.
❓ Predict Output
expert3:00remaining
What is the output of this nested Func delegate example?
Analyze this C# code using nested Func delegates. What will be printed?
C Sharp (C#)
Func<int, Func<int, int>> add = x => y => x + y; var addFive = add(5); Console.WriteLine(addFive(10));
Attempts:
2 left
💡 Hint
The outer Func returns another Func that adds two numbers.
✗ Incorrect
The outer Func takes x and returns a Func that takes y and returns x + y. add(5) returns a Func adding 5 to its input. addFive(10) returns 15.