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

Func delegate type in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Func Delegate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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));
A12
BError at compile time
C34
D7
Attempts:
2 left
💡 Hint
Func delegates can take parameters and return a value. Here it multiplies two integers.
Predict Output
intermediate
2: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());
AError: Func must have parameters
Bgreet
CHello World!
Dnull
Attempts:
2 left
💡 Hint
Func can have zero parameters and return a value.
🔧 Debug
advanced
2: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();
AOutput: 1
BRuntime error: NullReferenceException
COutput: 0
DCompile-time error: No overload for 'square' takes 0 arguments
Attempts:
2 left
💡 Hint
Check how many arguments the Func delegate expects.
🧠 Conceptual
advanced
2: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?
A16
B8
C4
DNo limit
Attempts:
2 left
💡 Hint
Check the official Microsoft documentation for Func delegates.
Predict Output
expert
3: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));
A510
B15
C5
DCompile-time error
Attempts:
2 left
💡 Hint
The outer Func returns another Func that adds two numbers.