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

Lambda expression syntax in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Lambda Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple lambda expression
What is the output of this C# code snippet?
C Sharp (C#)
Func<int, int> square = x => x * x;
Console.WriteLine(square(5));
ACompilation error
B25
C10
D5
Attempts:
2 left
💡 Hint
The lambda takes an integer and returns its square.
Predict Output
intermediate
2:00remaining
Lambda with multiple parameters and statement body
What will this code print?
C Sharp (C#)
Func<int, int, int> addAndMultiply = (a, b) => {
    int sum = a + b;
    return sum * 2;
};
Console.WriteLine(addAndMultiply(3, 4));
A14
B7
C12
DCompilation error
Attempts:
2 left
💡 Hint
The lambda sums two numbers and then doubles the result.
Predict Output
advanced
2:00remaining
Lambda capturing outer variable
What is the output of this code?
C Sharp (C#)
int factor = 3;
Func<int, int> multiply = x => x * factor;
factor = 5;
Console.WriteLine(multiply(4));
ACompilation error
B15
C12
D20
Attempts:
2 left
💡 Hint
Lambdas capture variables by reference, not by value.
Predict Output
advanced
2:00remaining
Lambda with incorrect syntax
Which option will cause a compilation error?
C Sharp (C#)
Func<int, int> f = x => x * 2;
AFunc<int, int> f = (x) => x * 2;
BFunc<int, int> f = x => { return x * 2; };
CFunc<int, int> f = x => { x * 2; };
DFunc<int, int> f = (int x) => x * 2;
Attempts:
2 left
💡 Hint
Check if the lambda body returns a value properly.
🧠 Conceptual
expert
2:00remaining
Understanding lambda expression type inference
Given the code below, what is the inferred delegate type of the lambda expression?
C Sharp (C#)
var list = new List<int> {1, 2, 3};
var result = list.Select(x => x.ToString());
AFunc<int, string>
BAction<int>
CPredicate<int>
DFunc<string, int>
Attempts:
2 left
💡 Hint
Select expects a function that takes an int and returns a string.